Wednesday, May 1, 2013

C program to get the area of a circle

The c program given below will calculate the area of circle after getting the radius. We know that, area of a circle = πr2. Now, if we need to find out the area of a circle then we need to know the radius only. Because, the value of π is constant (3.1416).

That's why just after running the program, you will get a message to provide the radius of the circle. After providing the radius, soon the area of the circle will be calculated and will be displayed on the screen.

In the 6th line there I have declared two float type variables radius and area. We will use the variable radius to store the radius of the circle after getting input from keyboard. By the 9th line a message will be displayed asking to input the radius. When you will provide the input, then it will be received and stored to the variable radius by the 12th line.

By the 15th line area of the circle will be calculated and the result will be stored into the variable area. Later, by the 18th line the result will be displayed.
c program,computer programming,area of circle
//c program to get the area of a circle
#include<stdio.h>
//main function
void main(){
    //declaring float type variables
    float radius, area;
    
    //displaying message to input the radius
    printf("Enter the Radius of the Circle: ");
    
    //getting data into the float type variable
    scanf("%f",&radius);
    
    //calculation to get the area of a circle
    area=3.1416*radius*radius;
    
    //displaying the result
    printf("The Area of the Circle is: %.2f",area);
}


No comments:

Post a Comment