Answer to Question #287583 in C for freddiee

Question #287583

Write a program in c language that could prompt the user to select a mathematical figure either circle or rectangle . The program then compute the perimeter of the figure.

1
Expert's answer
2022-01-14T13:46:00-0500
#include <stdio.h>


int main()  
{  
	int figure; 
	float perimeter;
	float radius;
	float length;
	float width;
	printf("1. Circle\n");
	printf("2. Rectangle\n");
	printf("Select a mathematical figure: ");
	scanf("%d",&figure);


	if(figure==1 ){
		printf("Enter the radius of the circle: ");
		scanf("%f",&radius);
		perimeter =2*3.14*radius;
		printf("The perimeter: %.2f\n\n",perimeter);
	}else if(figure==2 ){
		printf("Enter the length of the rectangle: ");
		scanf("%f",&length);
		printf("Enter the width of the rectangle: ");
		scanf("%f",&width);
		perimeter =2*(width+length);
		printf("The perimeter: %.2f\n\n",perimeter);
	}else{
		printf("\nWrong selection\n");
	}


	getchar();
	getchar();
	return 0;  
}  

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS