Program to calculate area and perimeter of rectangle, sqare and circle using C language

 
         
       
Shape
Area
Perimeter
Rectangle
Length x width
2*(length+width)
Square
Side x side
Side x 4
Circle
πr2
2πr


#include <stdio.h>
int main()
{
int length,width,side;
float radius,pi=3.14;
int a_rect,p_rect,a_sq,p_sq;
float a_cir,p_cir;

printf("Enter length and width for rectangle\n");
scanf("%d%d",&length,&width);
printf("Enter sides of the square\n");
scanf("%d",&side);
printf("Enter radius of the circle\n");
scanf("%f",&radius);
a_rect=length*width;
p_rect=2*(length+width);
a_sq=side*side;
p_sq=4*side;
a_cir=pi*radius*radius;
p_cir=2*pi*radius;
printf("For rectangle:Area=%d, Perimeter.=%d\n",a_rect,p_rect);
printf("For square:Area=%d, Perimeter=%d\n",a_sq,p_sq);
printf("For circle:Area=%f, Perimeter=%f\n",a_cir,p_cir);
}

OUTPUT:
Enter length and width for rectangle
18 15
Enter sides of the square
12
Enter a radius of the circle
6.5
For rectangle:Area=270, Perimeter.=66
For square:Area=144, Perimeter=48

For circle:Area=132.664993, Perimeter=40.820000



No comments:

Post a Comment

For any doubt or suggestion you can write here