Question

In: Computer Science

2) Write an algorithm to compute the area of circles. Your algorithm should prompt the user...

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

Solutions

Expert Solution

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


Related Solutions

write a program to perform the following in C Your program should prompt the user to...
write a program to perform the following in C Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings. After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case. Once the list is in alphabetical order, the list should be output to the console in order. The program should execute...
Write a program that calculates the salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user...
rite a program that will calculate the perimeter and area of a rectangle. Prompt the user to input the length and width. Calculate the area as length * width. Calculate the perimeter as 2* length + 2* width. Display the area and perimeter. Please use a proper heading in a comment block (name, date, description of the program). Please use comments in your code. Run your program twice using different input. Copy the output and place it at the bottom...
3. a) Write a script to prompt the user for the length and width of a...
3. a) Write a script to prompt the user for the length and width of a rectangle, and print its area with two decimal places. Put comments in the script. b) Convert the script in part (a) to a function.
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm....
The prompt is using Python:  Write a 3 rail transposition encryption algorithm, and a corresponding decryption algorithm. Implement these two algorithms in their own function. Now write a testing function that demonstrates your algorithms work for all interesting cases!
Write a program to compute 2 point Gauss quadrature on a single interval. Your input should...
Write a program to compute 2 point Gauss quadrature on a single interval. Your input should be a function with f,a,and b. Verify it by checking that the error in using the rule for f(x)=x^3 - 3x^2 +x - 7 is zero. In matlab please.
Program should be written in Java b) The computer program should prompt the user (You are...
Program should be written in Java b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out...
User the Scanner class for your input Write a java program to calculate the area of...
User the Scanner class for your input Write a java program to calculate the area of a rectangle. Rectangle Area is calculated by multiplying the length by the width   display the output as follow: Length =   Width = Area = Load: 1. Design (Pseudocode ) 2. Source file (Java file, make sure to include comments) 3. Output file (word or pdf or jpig file)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT