Read the problem statement. Formulate the algorithm using pseudocode and top-dow
ID: 3674462 • Letter: R
Question
Read the problem statement. Formulate the algorithm using pseudocode and top-down, stepwise refinement. Write the C program. Test, debug and execute the C program. Write a program that reads in the radius of a circle and prints the circle's diameter, circumference and area. Use the constant value 3.14159torn. Perform each of these calculations inside the printf statement(s) and use the conversion specifier %f. [In chapter 2, we have discussed only integer constants and variables. In Chapter 3 we will discuss floating-point numbers, i.e., values that can have decimal points.]Explanation / Answer
#include<stdio.h>
#define PI 3.14159
void main()
{
float radius, diameter, circumference, area;
printf("Enter Radius of a Circle : ");
scant("%f", &radius);
printf(" Diameter of the Circle is : %5f", (2*radius)); // diameter is 2*r
printf(" Circumference of the Circle is : %5f", ( 2*PI*radius)); // Circumference is 2*PI*r
printf( " Area of the Circle is : %5f", ( PI*radius*radius)); // Area is PI*r*r
}
Output:
Enter Radius of a Circle : 2.5
Diameter of the Circle is : 6.28318
Circumference of the Circle is : 15.70795
Area of the Circle is : 19.63493
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.