Write a program that computes the area of each color in an archery target. For s
ID: 3746336 • Letter: W
Question
Write a program that computes the area of each color in an archery target. For simplicity, we will consider a simple circular archery target consisting of the colors (in order from inside to outside): yellow, red, blue, black, and white. We also assume that each color in the target is equal 'width'. You must prompt the user for a radius (in cm) of the entire target and report the following information: The area of each colored section. Output only four decimal places. a. b. The percentage (using DecimalFormat) of each colored section (compared to the area of the entire target). You must output the information, in color order, according to the following example. The color yellow has area 3.1416 cm^2 with 4% of the total area.Explanation / Answer
Program to count area of target in C laguage:
#include<stdio.h>
void main(){
float r;
printf("Enter radius of entire target(in cm): ");
scanf("%f",&r);
if(r<=0){
printf("Radius should be positive");
return;
}
float w=r/5;
float areaYellow = 3.1415 * w * w;
float areaRed = 3 * 3.1415 * w * w; // pi*(2w)^2 - pi*(w)^2 = 3* pi*w*w
float areaBlue = 5 * 3.1415 * w * w; // pi*(3w)^2 - pi*(2w)^2 = 5* pi*w*w
float areaBlack = 7 * 3.1415 * w * w; // pi*(4w)^2 - pi*(3w)^2 = 7* pi*w*w
float areaWhite = 9 * 3.1415 * w * w; // pi*(5w)^2 - pi*(4w)^2 = 9* pi*w*w
float total = 3.1415 * r*r;
printf("The color yellow has area %f cm^2 with %f% of the total area.",areaYellow ,areaYellow *100/total);
printf("The color red has area %f cm^2 with %f% of the total area.",areaRed ,areaRed *100/total);
printf("The color blue has area %f cm^2 with %f% of the total area.",areaBlue ,areaBlue *100/total);
printf("The color black has area %f cm^2 with %f% of the total area.",areaBlack ,areaBlack *100/total);
printf("The color white has area %f cm^2 with %f% of the total area.",areaWhite ,areaWhite *100/total);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.