Programming in C; Area of Circle Explanation

Programming in C; Area of Circle Explanation

#include<stdio.h> 
 int main() {
    float r, Area,  Perimeter;
    printf(“Enter the radius of circle”);
    scanf(“%f”,&r); 
    Area = 3.14*r*r; 
    Perimeter=2*3.14*r;
    printf(“the area of the circle is %f\n”,Area);
    printf(“the perimeter of the circle is %f\n”,Perimeter); 
   return 0; 
}

In the above code, Area and Circumstances of a circle are displayed as output. The value of the radius is taken from the user as input.

In c programming every keyword has its own meaning.

1. #include<stdio.h>

This is the starting line of the programming . We can further divide the word for more clarification.

We can further divide the word for more clarification.

  1. #include It is pronouns as “has included”. It is a directive to include the header file in the source code.
  2. <stdio.h> It is a header file of the program that contains the function of standard input/output and enclosed in angular bracket. It is the most used header file during programming.

 2. int main(){} 

It represents the main part of the programming. Hence it is called the main function. Here, main is the name of the method and () occur with the method which represents the return type of the program .since,it does not contain any value so the empty argument is sent in the method. {} is a place for the body where the code inside it is executed.

 3. float r, Area, Perimeter;

This is the declaration part of the variables. The variables which we will be using throughout the modules are declared here. Here the symbol “ ; ” refers to the termination of that line.

  1. float –It defines the variable types. In this case, it represents the floating values (2.00,5.21,87.2365)
  2. r, Area, Perimeter– These are the variable declared where r is supposed for the radius of the circle, Area for the area of a circle, and perimeter for the perimeter of the circle.

 4. printf(“ Enter the radius of circle ”);

This line refers to printing the strings. Here it is just printed to show the user some instruction to carry on.

  1. printf(“ ”)printf is used for displaying the output on the screen. The output to be displayed is enclosed by a small bracket and encoded by “ ” to convert the values into strings form. Here, “ Enter the radius of circle ” is the output to be displayed.

 5. scanf(“%f”,&r);

This line is used for storing the values entered by the user into the variable declared.

  1. scanf() is used for taking the user input and initializing it to the variable.
  2. %f represents the floating value. It is symbolized by %f. Here, It tells the reader that the variable contains floating value.
  3. &r is the initialization part. The value enters by the user is stored in this variable. It is denoted by ampersand r (&r). Here, the radius enter by the user is store in variable r.

6. Area = 3.14*r*r;

It is the logical station of the program. The formulas or way of finding some output is done in this part. The variable is assigned with some values that it should execute and the final value of execution is store on that variable.

Here, the Area variable has some mathematical calculations to carry on. The value is assigned by equals to (=) sign. The value of pie is written and double multiplication of variable r is done as for square of r which calculate the area of circle and store it to variable Area.

7. Perimeter=2*3.14*r;

This step is similar to the upper step. Here, Perimeter variable has some mathematical calculation to carry on. The value is assigned by equals to (=) sign. According to the circumstances of circle formula, 2 is multiplied with the value of pie and again multiplied with the radius of circle(r).

8. printf(“the area of the circle is %f\n”,Area);

As above printf is used for displaying output. Here, displaying the output is slightly different than the above case. In this case, we display the strings with the value of the variable . Inside the small brackets () and double apostrophic’s(“ ”), %f is used for the value representation and outside of it after the commas(,), the name of the variable is written. Here, the Area value is displayed with the string.

9. printf(“the perimeter of the circle is %f\n”,Perimeter);

This line is similar as the above line. The difference is that the perimeter variable is written to print the circumstance of a circle.

10. return 0;

It is the keyword that returns the value need to the method. As the return type of the method is int so the method returns 0 to satisfy the condition provided.

In this way the area and circumstance of circle is calculated. Similarly, we can use same techniques to calculate the area and perimeter of other shape. Everythings remain same except the variable need to calculation and formula to calculate it.

Blog by : Yubraj Upreti,

BCS Hons.

Sunway International Business School.

Share this on facebook

Subscribe to our Youtube Channel

Leave a comment

Your email address will not be published. Required fields are marked *