C program to calculate perimeter and area of a rectangle.Take length and breadth of ractangle as input.
//C program to calculate perimeter and area of rectangle
#include <stdio.h>
float widthOfRectangle, heightOfRectangle, areaOfRectangle, perimeterOfRectangle;
int main() {
printf("Enter width of rectangle : \n");
scanf("%f", &widthOfRectangle);
printf("Enter height of rectangle :\n");
scanf("%f", &heightOfRectangle);
//Perimeter of ractangle = 2*(width + height)
perimeterOfRectangle = 2*(widthOfRectangle + heightOfRectangle);
printf("Perimeter of the rectangle = %f\n", perimeterOfRectangle);
//Area of rectangle = width * height
areaOfRectangle = widthOfRectangle * heightOfRectangle;
printf("Area of the rectangle = %f\n", areaOfRectangle);
return(0);
}
Output:
Post a Comment
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.