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.
#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;
}
Comments
Leave a comment