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 binary search algorithm in C language by performing following steps: Prompt the user to...
Write a binary search algorithm in C language by performing following steps: Prompt the user to enter the number of array elements (say, N).   Read the N different values (define these values to be of type integer).   Read the element (integer value) which you want to search. Invoke a function to display the values in the array. The function should take the array reference and number of elements as arguments and should have the return type as void. The function...
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...
Write a program that will input the information for 2 different employees. Prompt the user for...
Write a program that will input the information for 2 different employees. Prompt the user for the first employee’s name, hours worked and rate. Compute the salary and display it. Do the same for the second and third employees. Then, display a message to the effect that the highest salary is whatever and the lowest salary is whatever. When the program runs, the following should display information should line up just as I have it below. E:\> java Quiz4 Name:...
Design an algorithm to prompt user to enter a number. Determine the number is odd or...
Design an algorithm to prompt user to enter a number. Determine the number is odd or even with Case Logic.
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...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT