Pages

Sunday, 28 January 2018

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

The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.
/* This program takes length and breadth of rectangle and radius of a circle from
user as input then finds area and perimeter of the rectangle and the circumference of t
he circle, then shows results.*/
#include<stdio.h>
#include<conio.h>
int main()
{
    /*Declaring and initializing variables*/
    float lengthrect = 0, breadthrect =0, radius =0, area =0, perimeter =0, circumference =0 ;
  
    /*Taking input from user*/
    printf("Please enter the length of Rectangle: ");
    scanf("%f",&lengthrect);
    printf("\nNow enter the breadth of Rectangle: ");
    scanf("%f",&breadthrect);
    printf("\nNow enter the radius of circle: ");
    scanf("%f",&radius);
  
    /*Calculations*/
    area = lengthrect * breadthrect;
    perimeter = 2 * (breadthrect + lengthrect);
    circumference = 2 * 3.1416 * radius;
  
    /*showing results*/
    printf("\n\nResults: \n");
    printf("__________");
    printf("\nArea of the Rectangle: %f units\n",area);
    printf("\nPerimeter of the Rectangle: %f units\n",perimeter);
    printf("\nCircumference of the circle: %f units \n",circumference);
    getche();
    return 0;

}