Write up a program that allows the user to calculate the are

Write up a program that allows the user to calculate the area, perimeter, or the diameter of a circle based on a radius input. Therefore, ask the user for the radius first. Then, ask which calculation he wants to make. Only allow him to make one calculation per run of the program. Use if statements to print only one calculation

Solution

#include <stdio.h>
int main()
{
float radius, diameter, circumference, area;

//Reads radius of circle from user

printf(\"Enter radius of circle: \");

scanf(\"%f\", &radius);

/*

* Calculates diameter, circumference and area of circle

*/

diameter = 2 * radius;

circumference = 2 * 3.14 * radius;

area = 3.14 * (radius * radius);

printf(\"\ Diameter of circle = %.2f units.\ \", diameter);

printf(\"Circumference of circle = %.2f units.\ \", circumference);

printf(\"Area of circle = %.2f sq. units.\", area);

return 0;

}

Write up a program that allows the user to calculate the area, perimeter, or the diameter of a circle based on a radius input. Therefore, ask the user for the r

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site