In: Computer Science
2) Write an algorithm to compute the area of circles. Your algorithm should prompt the user to take the number of circles and their radius values. Then it should compute the areas of each circle. Finally, your algorithm will print both radius and area of all circles into the output. [N.B. you need to use iterative statement for solving the problem. Consider Pi = 3.14159] Input: Area of how many Circles you want to compute? 3 Key in radius values: 2.5 3.12 2.16 Output: Radius is 2.5 and the Area is 19.63 Radius is 3.12 and the Area is 30.76 Radius is 2.16 and the Area is 14.65
C program
If you need any corrections/ clarifications kindly comment.
If you like the answer please give a Thumps Up
Algorithm
Step1 : Start
Step 2: Read into n, the area of how many Circles to be
computed.
Step 3: Read the radius values into array radius[n].
Step 4:Calculate the area of each circle ,
area=3.14*radius2
Step 5:Print the radius and area of each circle.
Step 6: Stop
C Program
#include <stdio.h>
int main()
{
int n,i;
float pi=3.14;
printf("Area of how many Circles you want to
compute?");
scanf("%d",&n);
float radius[n],area[n];
printf("Enter the %d radius values :",n);
for(i=0;i<n;i++)
{
scanf("%f",&radius[i]);
area[i]=pi* radius[i]*radius[i];
}
for(i=0;i<n;i++)
printf("Radius is %.2f and the area is
%.2f\n",radius[i],area[i]);
return 0;
}
Output
Area of how many Circles you want to compute?3
Enter the 3 radius values :2.5 3.12 2.16
Radius is 2.50 and the area is 19.62
Radius is 3.12 and the area is 30.57
Radius is 2.16 and the area is 14.65