write c program to Find the Area and Circumference of a Circle

Ram Pothuraju

 #include <stdio.h>


int main()

{

    float radius, area, circumference;

    

    printf("Enter the radius of the circle: ");

    scanf("%f", &radius);

    

    // Calculate the area of the circle

    area = 3.14159 * radius * radius;

    

    // Calculate the circumference of the circle

    circumference = 2 * 3.14159 * radius;

    

    printf("The area of the circle is: %.2f\n", area);

    printf("The circumference of the circle is: %.2f\n", circumference);

    

    return 0;

}



In this program, we first declare three variables - radius, area, and circumference - all of which are floating-point numbers.


Then, we prompt the user to enter the radius of the circle using the printf and scanf functions.


Next, we calculate the area of the circle using the formula pi * radius * radius, where pi is approximately equal to 3.14159. We store the result in the area variable.


Similarly, we calculate the circumference of the circle using the formula 2 * pi * radius and store the result in the circumference variable.


Finally, we print the results using the printf function, using the %.2f format specifier to round the values to two decimal places.


When the program is run, it will output the area and circumference of the circle based on the user's input.



Post a Comment

0Comments

Post a Comment (0)