Saturday 15 October 2011

(e) 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;
}
   
   


6 comments:

  1. area of cicle is not being calculated by above prog. plz help

    ReplyDelete
    Replies
    1. area of circle can be calculated by giving an instruction i.e;
      aoc=3.14*radius*radius;
      because formula is pi.r^2
      where pi=3.14

      Delete
  2. area of circle can be calculated by giving an instruction i.e;
    aoc=3.14*radius*radius;
    because formula is pi.r^2
    where pi=3.14

    ReplyDelete
  3. How to do if the program have looping? sorry my english bad

    ReplyDelete
  4. How to do if the program have looping? sorry my english bad

    ReplyDelete