Area programs in C

Operator based programs, in this article we will see how we can use mathematical operators (+, -, *, /, %) in programs

// Area of circle,
// area= πr
// perimeter= 2πr

#include<stdio.h>
#include<conio.h>
int main(){
float r,area,pi,peri;
pi=3.14;
printf("Enter circle radius:");
scanf("%f",&r);
area=pi*r*r;
peri=2*pi*r;
printf("Area of circle=%f \n",area);
printf("Perimeter of circle=%f \n",peri);
return 0;
}

 

// Area of right angle triangle
// area=(base*height)/2
// perimeter=base+height+hypotenuse

#include<stdio.h>
#include<conio.h>
int main(){
float base,height,h,area,peri;
printf("Enter height:");
scanf("%f",&height);
printf("Enter width:");
scanf("%f",&width);
print("Enter hypotenuse:");
scanf("%f",&h);
area=(base*height)/2;
h=base+height+h;
printf("Area of triangle=%f \n",area);
printf("Perimeter of triangle=%f \n",peri);
return 0;
}

 

 

// Area of square
// area=side*side
// perimeter=4*side

#include<stdio.h>
#include<conio.h>
int main(){
float side,area,peri;
printf("Enter square side:");
scanf("%f",&side);
area=side*side;
peri=4*side;
printf("area of square=%f \n",area);
printf("perimeter of square=%f \n",peri);

return 0;
}

 

// area of a rectangle
// area=length*width
// perimeter=2*(length+width)

#include<stdio.h>
#include<conio.h>
int main(){
float length,width,area,peri;
printf("Enter length:");
scanf("%f",&length);
scanf("%f",&width);
area=length*width;
peri=2*(length+width);
printf("Area of rectangle=%f \n",area);
printf("Perimeter of rectangle=%f \n",peri);return 0;

}

Post written by: Hemant Singh
© 2020 - 2020 All rights are reserved