C-Program to find the Area and Perimeter of a Reactangle and Square

#include  <stdio.h>
#include <conio.h>
 
void main()
{
	float side, area, perimeter, length, breadth;
	int choice;
	printf("**************************\nProgram to find the area and perimeter \n**************************\nPlease enter your choice: \n\n 1 for Square \n 2 for Rectangle\n");
	scanf("%d", &choice);
 
	switch (choice)
	{
	case 1:
		printf("Please Enter the side of square : ");
		scanf("%f", &side);
		area = side*side;
		perimeter = 4 * side;
		printf("The area of the square is : %f", area);
		printf("\nThe perimeter of the square is : %f", perimeter);
		printf("\n");
		break;
 
	case 2:
		printf("\n\nPlease enter the length of rectangle: ");
		scanf("%f", &length);
		printf("Please enter the breadth of rectangle: ");
		scanf("%f", &breadth);
		area = length*breadth;
		perimeter = 2 * (length + breadth);
		printf("\nThe area of the rectangle is : %f", area);
		printf("\nThe perimeter of the rectangle is : %f", perimeter);
		printf("\n");
		break;
	default:
		printf("\nWrong choice..Sorry\n");
	}
 
	getch();
}
Capture
Output
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s