Monday, April 13, 2009

Exercise Solving 5

Exercise 5:
The length and breadth of a rectangle and radius of a circle are input through the keyboard. Write a C program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.
Solution:

#include<stdio.h>
#include<conio.h>

void main()
{
float l, b, r, ar_rec, ar_circ, perm, cirm, pi=22/7;
printf(“Please enter the length and breadth of the rectangle: ”);
scanf(“%f %f”, &l, &b);
printf(“\nPlease enter the radius of the circle = ”);
scanf(“%f”, &r);
ar_rec=l*b;
perm=2*(l+b);
ar_circ=pi*r*r;
cirm=2*pi*r;
printf(“\nTherefore the area of the given rectangle is = %f unit square and perimeter is = %f unit”, ar_rec, perm);
printf(“\nAnd the area of the given circle is = %f unit square and circumference is = %f unit”, ar_circ, cirm);
getch();
}
In this program the values of length, breadth of the circle and the radius of the circle is to be inputted first by the user and then the calculation of the area & perimeter of the rectangle and the area & circumference of the circle is done, and then subsequently the result is then displayed to the user.
The output of the program is as follows:
Please enter the length and breadth of the rectangle: 5 3
Please enter the radius of the circle = 6
Therefore the area of the given rectangle is = 15 unit square and perimeter is = 16 unit
And the area of the given circle is = 113.1428 unit square and circumference is = 37.7142 unit

No comments:

Post a Comment

Please give your valuable comments or queries if you fell its helpful or if you like the contents of the site. Thanks...