Write a program that calculates the area and circumference of a circle. It should ask the user first to enter the number of circles n, then reads the radius of each circle and stores it in an array. The program then finds the area and the circumference, as in the following equations, and prints them in a tabular format as shown in the sample output. Area = πr2 , Circumference = 2πr, π = 3.14159
Sample Output:
Enter the number of circles: 4
Enter the radius of circle 1 : 10.5
Enter the radius of circle 2 : 5
Enter the radius of circle 3 : 30.7
Enter the radius of circle 4 : 12.5
Circle Radius Area Circumference
1 10.5 346.36 65.97
2 5 78.54 31.42
3 30.7 2960.92 192.89
4 12.5 490.87 78.54
((in java ))
Program code to copy:-
import java.util.Scanner;
import java.text.DecimalFormat;
public class Circle {
/**
* This program calculates the area and circumference of a circle.
* Program asks the user first to enter the number of circles n, then
* reads the radius of each circle and stores it in an array.
* Program then finds the area and the circumference and
* prints them in a tabular format.
*/
public static void main(String[] args) {
//Creating object of scanner class for user input
Scanner in = new Scanner(System.in);
//Creating object of DecimalFormat class to print the result upto 2 decimal places
DecimalFormat df = new DecimalFormat("0.00");
//Asking the number of circles from user
System.out.print("Enter the number of circles: ");
int num = in.nextInt();
//Allocating the memory for array to store the radius of circle
double radius[] = new double[num];
//Allocating the memory for array to store the calculated area of circle
double area[] = new double[num];
//Allocating the memory for array to store the calculated circumference of circle
double circumference[] = new double[num];
for(int i=0; i<num; i++)
{ //Reading the radius of each circle from user
System.out.print("Enter the radius of circle "+(i+1)+": ");
radius[i] = in.nextDouble();
//Calculating the area of each circle
area[i] = 3.14159 * radius[i] * radius[i];
//Calculating the circumference of each circle
circumference[i] = 2 * 3.14159 * radius[i];
}
//Printing the result in tabular format
//Printing heading
System.out.println("Circle\tRadius\tArea\tCircumference");
//Printing the area and circumference of circle for each radius given
for(int i=0; i<num; i++)
{
System.out.println((i+1)+"\t"+radius[i]+"\t"+df.format(area[i])+"\t"+df.format(circumference[i]));
}
}
}
Sample output:-
Write a program that calculates the area and circumference of a circle. It should ask the...
Write a shell script that given a radius, calculates the area of a circle. (Hint – don’t write this from scratch. Find another script that reads user input and performs a calculation, then modify it to meet your needs.) Save the script in your home directory with the name circle.sh The formula for calculating the area is: Area=Π*Radius2 You can use 3.14 for Π, and either do Radius*Radius or Radius^2 to get the square of the radius. Use the scale...
Write a function that prints the area and circumference of a circle for a given radius. Only the radius is passed to the function. The function does not return any values. The area is given by π r2 and the circumference is 2 π r.
Using the algorithm information below, program a calculator for the area and circumference of a circle. Answer in C LANGUAGE !! Algorithm for Area and Circumference of a Circle: Inputs: - radius of the circle Outputs: - the area of the circle - the circumference of the circle Relevant Constants and Formulas: - area of a circle = PI x Radius x Radius - circumference of a circle = 2 x PI X Radius Main Algorithm (numbered steps) 1. Input...
Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...
Please upload screenshots of the code. Thank you! P1 - Circle Area and Circumference functions.cpp, functions.h, P1.cpp The user enters 3 floating-pointer numbers which correspond to 3 radi. Store these numbers in an array. Then, define and prototype a function void area and cireffloat* area, float circumference, float array) which takes as input the array of circumferences of circles with the input radii. Think about why we need to pass pointers for both the area and the circumference variables. radii...
Write a program that prompts for and reads the Circumference of a circle as a floating point value (double) then print the radius of the circle
Write a java program that compute the circumference and area of a circle from the user input for a radius.
C++ programming question will upvote A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...
Write a program using the class to find out the area of a circle and volume of a cylinder. [* area of a circle=πr2, the volume of a cylinder=πr2*h where h is the height of the cylinder and r is the radius of the circular end of the cylinder] 1. The member variable should be private 2. Use public member functions to execute your program. 3. Use set ( ) function to access the private members 4. Use another approach...
Calculate the area and perimeter(circumference) of a circle. Print the area and perimeter(circumference) Use a radius of 15 to test your program, calculations should have 2 decimal places. In C++, please use visual studios, and show the output.