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.

7. To answer this question please submit the main.c file with your code.

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

Homework Answers

Answer #1
  • Below is the detailed solution of the problem mentioned above in C with code and output with screenshot
  • Please read the comments mentioned in the code for better understanding.
  • 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){
//input radius
printf("Enter the radius of a circle: ");
scanf("%lf",&r);
check=1;
}
//other than first time prompting
else{
//input radius
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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python program to calculate the area of a circle. The user needs to input...
Write a Python program to calculate the area of a circle. The user needs to input the value of the radius of the circle. area = 3.14 x radius x radius You should use a function named circlearea to perform the calculation 3. Write a Python program to calculate the area of a square. The user needs to input the value of the length of the square. area = len*len You should use a function named squarearea to perform the...
Complete the program to calculate and print the circumference and area of a circle, rounded to...
Complete the program to calculate and print the circumference and area of a circle, rounded to the nearest tenth (1 decimal place). The starter code already prompts the user and takes in the radius as a double-value input. You need to do the calculations and print the results. I recommend using the printf() command (described in chapter 3 of the book) to print the results with the correct rounding. import java.util.Scanner; class Circle { static Scanner sc = new Scanner(System.in);...
Listing 1 shows ABCD.cpp program to compute diameter, circumference and area for a circle with r,...
Listing 1 shows ABCD.cpp program to compute diameter, circumference and area for a circle with r, radius without user-defined function. Listing 2 shows the expected output of ABCD.cpp on the screen after creating user-defined functions for 3 circles of radius. Write a complete code to compute an output of 3 circles with r, radius as shown in Listing 2. Your answer should have four (4) functions as stated below as function declaration. double displayRadius(double); double displayDiameter(double); double displayCircumference(double); double displayArea(double);
ALL IN PYTHON PLEASE Problem 4 Write a program to compute the area of a circle...
ALL IN PYTHON PLEASE Problem 4 Write a program to compute the area of a circle some 'n' times. You must accept n and r from the user. Area is calculated using (22/7.0)*r*r - where r is the radius. Implement using value-returning functions. Hint: create a function to calculate area taking r as a parameter. In the main() function, ask for n and create a loop where you input r and invoke the area function n times. Rubric: Correct use...
Please use Python programming language to write a client program and a server program, so that...
Please use Python programming language to write a client program and a server program, so that these two programs communicate through a TCP connection based on the following scenario: Both of the client program and the server program are running on the same localhost. The client program prompts the user to enter the radius of a circle and pass it to the server program. The server program computes the area of this circle and passes it to the client program....
Write a C# source code. Write a function called CircArea() that finds the area of a...
Write a C# source code. Write a function called CircArea() that finds the area of a circle. It should take an argument of type double and return an argument of the same type. Write a Main() method that gets a radius value from the user, calls CircArea(), and displays the result.
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of...
Create a flowgorithm program to calculate the Area of Circle first then do the Circumference of Circle. The user will have the ability to convert Area OR the Circumference. That means we need to add a decision structure to the program. Furthermore, they need to be able to do it as many times as they want. That means we need to add a main loop structure to the program. The user will also have the choice of whether to run...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
In this lab, you complete a partially prewritten C++ program that uses an array. The program...
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help...