Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Breaking

Post Top Ad

Your Ad Spot

Tuesday, July 12, 2022

C program to calculate area and circumference of circle


C program to calculate the area and circumference of the circle 




Introduction:


This article will teach you how to write a C program to calculate the area and circumference of a circle. The program will take the user's radius input and calculate and display the area and circumference based on that radius. This program is useful for students studying computer science for the Secondary Education Examination (SEE) and the National Examination Board (NEB) of Nepal.

Understanding the Circle Concept


Before we begin, let's take a quick look at the concept of a circle. A circle is a perfectly round geometric shape made up of all points in a plane that are equidistant from a fixed center point. The radius of the circle is the distance from the center of the circle to any point on its circumference.


The Formula to Find the Area and Circumference of a Circle


The formulas for finding the area and circumference of a circle are as follows:
  • Area = Ï€r²
  • Circumference = 2Ï€r
where π is a mathematical constant with an approximate value of 3.14.

Coding:


/*area and circumference of circle*/

#include<stdio.h>

#include<math.h>

#define PI 3.1415

main()

{

float r,ar,cr;

printf("Enter radius=");

scanf("%f",&r);

ar=PI*pow(r,2);

cr=2*(PI*r);

printf("Area of circle=%f\n",ar);

printf("Circumference of circle =%f",cr);

}


Explanation of the program:


This C program calculates the area and circumference of a circle based on the user-input radius. It begins by including the necessary header files for input/output operations and mathematical functions. The value of Pi is defined as a constant using the #define preprocessor directive. The program then declares variables r (radius), ar (area), and cr (circumference) as floating-point numbers. The user is prompted to enter the radius, which is stored in the variable r using the scanf function. The area of the circle is calculated using the formula ar = PI * pow(r, 2), where pow is the function for exponentiation. Similarly, the circumference is calculated using the formula cr = 2 * (PI * r). Finally, the program prints the calculated area and circumference using the printf function.




Output:




Conclusion:


Finally, we have written a C program that calculates the area and circumference of a circle. This program is useful for students preparing for the SEE and NEB in computer science because it helps them understand circle concepts and apply formulas to calculate area and circumference.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages