Experiments-1

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


/* 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>

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);

    return 0;
}



OUTPUT :
__________

Please enter the length of Rectangle: 6.6                                                                                                                                       
Now enter the breadth of Rectangle: 4.5                                                                                                                                         
Now enter the radius of circle: 3.9                                                                                                                                             
                                                                                                                                                                                
                                                                                                                                                                                
Results:                                                                                                                                                                        
__________                                                                                                                                                                      
Area of the Rectangle: 29.699999 units                                                                                                                                         
Perimeter of the Rectangle: 22.200001 units    
Circumference of the circle: 24.504480 units  

No comments:

Post a Comment

Note: only a member of this blog may post a comment.