c program to enter the length and width of a rectangle and calculate the area and perimeter.

c program to enter the length and width of a rectangle and calculate the area and perimeter.

 


Write a program to enter the length and width of a rectangle and calculate the area and perimeter.

#include<stdio.h>
int main()
{
    float length,width,area,perimeter;
    printf("Enter the length of rectangle: ");
    scanf("%f", &length);
    
    printf("Enter the width of rectangle: ");
    scanf("%f", &width);
    
    area = width*length;
   
    perimeter = 2*(length + width);
   
    printf("area of rectangle: %f\n", area);
    printf("perimeter of rectangle: %f\n", perimeter);
    
    return 0;
}

output 

Enter the length of rectangle: 12
Enter the width of rectangle: 4
Area of rectangle: 48.000000
Perimeter of rectangle: 32.000000

Post a Comment