C program to find area,perimeter of Square and Rectangle

If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().

#include<stdio.h>
main()
{
 int sarea,speri,side;
 int rarea,rperi,len,wid;

//Accepting side of square
 printf("Enter Side of square\n");
 scanf("%d",&side);

//Area of square
 sarea=side*side;
 printf("Area of Square=%d\n",sarea);

//Perimeter of square
 speri=4*side;
 printf("Perimeter of Square=%d\n",speri);
printf("----------------------------------------------\n");

//Accepting lenght and width
 printf("Enter Length and Width of Reactangle\n");
 scanf("%d%d",&len,&wid);

//Area of reactangle
 rarea=len*wid;
 printf("Area of Reactangle=%d\n",rarea);

//Perimeter of reactangle
 rperi=2*(len+wid);
 printf("Perimeter of Reactangle=%d\n",rperi);
}

OUTPUT:

Enter Side of square
5
Area of Square=25
Perimeter of Square=20
----------------------------------------------
Enter Length and Width of Reactangle
2 7
Area of Reactangle=14
Perimeter of Reactangle=18

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.