Friday, 28 March 2014
0
C Program 7: To find the area and perimeter of rectangle and circumference of circle
Aim: The length & breadth of a rectangle and radius of circle are input through the keyboard. Write a program to calculate the area and perimeter of the rectangle, and the circumference of the circle.
Theory: you need to know about three mathematical formulas and here you go.. This is the code..
//to find area and perimeter of rectangle and circumference of circle
#include<stdio.h>
#include<conio.h>
int main()
{
int l,b,i;
float r, area, peri, circum;
printf("Calculating the area and perimeter of rectangle\n");
printf("Enter the Length and breadth of rectangle: ");
scanf("%d%d", &l, &b);
peri= 2*(l+b);
area= l*b;
printf("The area of the rectangle is: %f\n", area);
printf("The perimeter of the rectangle is: %f\n", peri);
for(i=0; i<80; i++)
{
printf("*");
}
printf("\n");
printf("Calculating the radius of circle\n");
printf("Enter the radius of the circle\n");
scanf("%f", &r);
circum=2*3.14*r;
printf("The cirumference of the circle is: %f", circum);
getch();
return 0;
}
First we calculated the area and perimeter of rectangle using formulae:
scanf("%d%d", &l, &b);
peri= 2*(l+b);
Then we calculate the circumference of circle using formula: circum=2*3.14*r;
Ignore the for loop used inside the program. That isn't actually required. I just used it to make the output look more organized.
Here's the output:
Subscribe to:
Post Comments (Atom)
0 Responses to “C Program 7: To find the area and perimeter of rectangle and circumference of circle”
Post a Comment