Simple Programs

  • Doing Programs gives you the great understanding about what you have learned.
  • Doing Programs gives you the Confidence.
  • So let's Start by doing some programming.



  • Q1: Declare a constant "pi" with value=3.14 by keyword "const" and print the value of "pi" on the screen?
    #include<stdio.h>
    const float pi =3.14;
    
     void main(){
    printf("Constant Variable is %f",pi);
    }
    

    Output:

    Constant Variable is 3.14

    Exercise:

    Q:Declare a same constant "pi" through Macros,display the constant

    Hint: Use "#define pi 3.14",Bestofluck.


  • Q2:declare variable temp_c and assign 27.65C and convert it into Fahrenheit and display Fahrenheit as well as temperature in Celcius.

    Solution:

    #include<stdio.h>
    
    void main()
    {
    float temp_c,temp_f;
    temp_c = 27.65;       //temp_c variable
    temp_f = temp_c+273.15;         // temp_f variable
    
    
    printf("Temperature in Celsius is %f C\n",temp_c);
    
    
    printf("Temperature in Fahrenheit is %f F",temp_f);
    }
    

    Output:

    Temperature in Celsius is 27.65 C
    Temperature in Fahrenheit is 300.799988 F

    Exercise:

    Q:declare variable temp_f and assign 300.799988 and convert it into celsius and display Celsius as well as temperature in Fahrenheit.

    Hint: subtract 273.15 from temp_f variable,Bestofluck.


  • Q3: Declare variables radius assign 3.2 to it and Calculate Area of the circle and print the result

    Solution

    #include<stdio.h>
    #define pi 3.14
    void main()
    {
    float radius = 3.2;
    float Area;
    Area = pi*(radius*radius);       // radius*radius (method of taking square of  variable)
    printf("Area of the circle is %f",Area);
    
    }
    

    Output:

    Area of the circle is 32.153603.

    Exercise:

    Declare variables radius assign 3.2 to it and Calculate 



  •  Q:Circumference of the circle and print the result

    Hint:Formula for Circumference of circle is 2*pi*radius*radius,Bestofluck.


  • Some Maths equation in C

    Algebraic Equation in 'C'
    Maths Equations method to write in 'C'
    ij+k (i*j)+k
    i3 i*i*i
    i3+5 (i*i*i)+5