Question

# In C programming, Thank you Write a program to compute the area of a circle. You...

In C programming, Thank you

Write a program to compute the area of a circle.

You have to write a complete “C” program that compiles and runs in Codeblocks.

Program requirements:

1. Declare the variables needed: radius (r) and area (yourLastName).

2. Calculate and print the area of each circle.

3. The program MUST prompt the user for a new radius (r) over and over until the user types -1.

5. Use the type double for all decimal numbers.

6. When printing the resulting area of the circle please format the output results with a precision of 2 decimal places.

8. Your program must include a variable inside the main using your last name, use this variable to save the final result of each area calculation.

double yourLastName; // save the final result of the calculation

You will need the following information:

For PI use the number: 3.1416

Use the following formula: A = PI * (r^2)

For instance, if r=3 then A = (3.1416)*(3*3) = 28.27

The following is an example of how your program should look when you execute it:

Enter the radius of a circle: 2
The area of the circle is 12.57

Enter the radius of a NEW circle: 3
The area of the circle is 28.27

Enter the radius of a NEW circle: 4
The area of the circle is 50.27

Enter the radius of a NEW circle: -1

• Below is the detailed solution of the problem mentioned above in C with code and output with screenshot
• CODE:

#include<stdio.h>
#include<stdlib.h>

//driver function
int main(){
//constant value of pi used
double PI=3.1416;
//variable to store final area of the circle
double yourLastName;
//variable to store radius input by the user
double r;

//check variable to check if it is the first time or other than first as we
//are prompting differently.
int check=0;
//loop until user enters -1
while(1){
//first time prompting
if(check==0){
printf("Enter the radius of a circle: ");
scanf("%lf",&r);
check=1;
}
//other than first time prompting
else{
printf("Enter the radius of a NEW circle: ");
scanf("%lf",&r);
}
//if radius entered is -1 then break from loop
if(r==-1){
break;
}

//otherwise calculate the area of the circle
yourLastName= PI*(r*r);
//and print it on the screen.
printf("The area of the circle is %0.2lf\n",yourLastName);
}
//return from main()
return 0;
}

• INPUT/OUTPUT:

Enter the radius of a circle: 2
The area of the circle is 12.57
Enter the radius of a NEW circle: 3
The area of the circle is 28.27
Enter the radius of a NEW circle: 4
The area of the circle is 50.27
Enter the radius of a NEW circle: -1

• For better clarity below are the screenshot of the code and it's output attached.

CODE

INPUT/OUTPUT:

So if you have any doubt regarding this solution please feel free to ask it in the comment section and if it is helpful then please upvote this solution, THANK YOU.

#### Earn Coins

Coins can be redeemed for fabulous gifts.