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


#include<stdio.h>
int main()
{
    float l, b, r,ac, cc, ar, pr;  /*l is length,b is breadth,r is radius*/

    /*For rectangle*/
    printf("Enter the length of rectangle: ");
    scanf("%f",&l);
 
    printf("Enter the breadth of rectangle: ");
    scanf("%f", &b);

    /*For circle*/
    printf("\nEnter the radius of circle: ");
    scanf("%f", &r);

    /*Calculate area & perimeter of the rectangle*/
      ar = l * b;    /*ar is Area of Rectangle = Length x Breadth*/
      pr = 2 * (l + b);    /*pr is Perimeter of Rectangle = 2 x (L + B) or addition of all sides*/

     /*Calculate area & circumference of the circle*/
      ac = 3.14 * r * r;   /*ac is Area of Circle = 2 x Pi x r^2 where Pi = 3.14*/
      cc = 2 * 3.14 * r;  /*cc is Circumference of Circle = 2 x Pi x r*/

     printf("\n\nThe area of the rectangle: %f",ar);
     printf("\nThe perimeter of the rectangle: %f",pr);
     printf("\n\nThe area of the circle: %f",ac);
     printf("\nThe circumference of the circle: %f",cc);

     return 0;
}

-----------------------------------------
Output:

Enter the length of rectangle: 20
Enter the breadth of rectangle: 30

Enter the radius of circle: 5


The area of the rectangle: 600.000000
The perimeter of the rectangle: 100.000000

The area of the circle: 78.500000
The circumference of the circle: 31.400000

Comments

Post a Comment

Popular posts from this blog

Q: If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator ‘%’)