Example C Program

View


Length and Breadth of rectangle is input through the keyboard. Write a program in C to display the area and perimeter of rectangle.

/* Program to display area and perimeter of a rectangle [rectangle.c] */
#include < stdio.h >
#include < stdio.h >

void main ( )
{
               // Variable Declaration
               float len, wid;
               float area, peri ;
               clrscr ( );

               // Input
               printf ( “ \n Enter the Length \n “ );
               scanf ( “ %f “, &len );
               printf ( “ \n Enter the Breadth \n “ );
               scanf ( “ %f “, &wid );

               // Processing
               area = len * wid ;
               peri = 2 * ( len + wid );

               // Output
               printf ( “ \n Area = %f “, area );
               printf ( “ \n Perimeter = %f “, peri );
               getch ( );
}

Output

Enter the Length
10
Enter the Breadth
8
Area = 80
Perimeter = 36
Last modified: Tuesday, 21 September 2021, 9:40 AM