Area & Volume
calculate the area of circle
//PI*r*r
#include <stdio.h>
#include<math.h>
#define PI 3.142
int main()
{
int r;
float A;
printf("Enter the radius of circle\n");
scanf("%d",&r);
A = PI *r*r;
printf("\nThe Area of circle is A = %.2f",A);
return 0;
}
perimeter of circle
#include <stdio.h>
#include<math.h>
#define PI 3.142
int main()
{
int r;
float P;
printf("Enter the radius of circle\n");
scanf("%d",&r);
P = 2*PI *r;
printf("\nThe Perimeter of circle is P = %.2f",P);
return 0;
}
Find area of rectangle
#include<stdio.h>
int main()
{
int A,w,l;
printf("\nEnter width &length of rectangle");
scanf("%d%d",&w,&l);
A = w*l;
printf("Area of rectangle is A = %d",A);
return 0;
}
Find perimeter of rectangle
#include<stdio.h>
int main()
{
int P,w,l;
printf("\nEnter width &length of rectangle");
scanf("%d%d",&w,&l);
P = 2*(w+l);
printf("Area of rectangle is P = %d",P);
return 0;
}
C program to find the area of a triangle, given three sides
#include <stdio.h>#include <math.h>
int main()
{
int s, a, b, c, area;
printf("Enter the values of a, b and c \n");
scanf("%d %d %d", &a, &b, &c);
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));
printf("Area of a triangle = %d \n", area);
return 0;
}
}
Comments
Post a Comment