area of a circle c code example

Example 1: c circle area

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#define P 3.1415926535

int main() {
	int a, c;
	double b;
	
	printf("AREA OF A CIRCLE\n\n\n1: Direct formula\n2: Invers formula\n\nChose: ");
	scanf("%d", &c);
	
	switch (c)
	{
		case 1:
			printf("\nEnter radius value: ");
			scanf("%d", &a);
			
			b = a * a * P;
			
			printf("\nArea: %f\n\n", b);
			
			break;
			
		case 2:
			printf("\nEnter area value: ");
			scanf("%d", &a);
			
			b = sqrt(a / P);
			
			printf("\nRadius: %f\n\n", b);
			
			break;
	}
	
	if(c != 1 && c != 2)
	{
		printf("The value is not accepted\n\n");
	}

	system("pause");
}

Example 2: c program to find area of circle

#include <stdio.h>
#define PI 3.142
int main(){
    float R, A;
    printf("Enter the radius: \n");
    scanf("%f", &R);
    A = PI * R * R;
    printf("Area is: %f\n", A);
    
}

Tags:

C Example