Question

In: Computer Science

Write a simple C program to generate a chart of circle properties. Output chart “iteration” is...

Write a simple C program to generate a chart of circle properties. Output chart “iteration” is to be specified by user input. Your chart will include the radius, diameter, circumference, and Area values in a single table, and radius values will range from 0 to 50, floating point values, with three-decimal-place precision. Table should have all column entries right-justified and each column will have a heading above the entries. For example, assuming user enters a incrementation value of 5, the first few entries of the table could look something like:

Radius Diameter Circumference Area

———————————————————————

0.000 0.000 0.000 0.000

5.000 10.000 31.416 78.540

10.000 20.000 62.832 314.159

Use right alignment using printf() Diameter, Circumference, and Area must be used as functions. Output a blank line after every 10 radius entries.

C language Thanks!

Solutions

Expert Solution

//---------------- radius_chart.c ---------

#include<stdio.h>
//constant to define for PI VALUE
#define PI 3.14
//FUNCTION that returns the diameter for given radius.
float getDiameter(float radius)
{
   return 2 * radius;
}
//FUNCTION that returns the area for given radius.
float getArea(float radius)
{
   return PI * radius * radius;
}
//FUNCTION that returns the circumference for given radius.
float getCircum(float radius)
{
   return 2 * PI * radius;
}
//FUNCTION that prints the chart for given radius.
void printChart(float incRadius)
{
   //variables to store
   float area;
   float circum;
   float diameter;
   float range = 50.0;
   float radius;
   printf("\n Radius Diameter Circumference Area\n");
   printf("\n------------------------------------------------------\n");
   //from radius 0 to 50(range) increment by incRadius entered by user.
   int count = 0;
   for(radius = 0.0; radius <= range;radius += incRadius)
   {
       //get area,circumference and diameter
       area = getArea(radius);
       circum = getCircum(radius);
       diameter = getDiameter(radius);
       //use .3 to round by 3 decimal places, and right align the values
       //that are printed by using a number after %
       printf("%10.3f %10.3f %15.3f %15.3f\n",radius,diameter,circum,area);
       if(count%10 == 0 && count != 0)
       {
           printf("\n");
       }
       count++;
   }
}

int main()
{
  
   float incRadius;
   //get input for incremented radius
   printf("Enter Incrementation Value: ");
   scanf("%f",&incRadius);
   //if it is negative or zero print error msg and exit.
   if(incRadius <=(float) 0)
   {
       printf("Invalid Increment value. It should be >=1\n");
       printf("Exiting....");
       return 1;
   }
   //if not print the chart by passing input from user.
   printChart(incRadius);
   return 0;
}

//PLEASE LIKE THE ANSWER AND COMMENT IF YOU HAVE ANY DOUBTS.


Related Solutions

C++ Write a program that reads in two Integers. A starting number and a number of iterations. For each iteration, you generate a new number that is the result of reading off the number of same digits in the original number. output each Iteration
C++ Write a program that reads in two Integers. A starting number and a number of iterations. For each iteration, you generate a new number that is the result of reading off the number of same digits in the original number. output each Iteration.   Example starting number 331 next number [iteration 1]:"2 threes and 1 one" = 231 next number [iteration 2]:"1 two, 1 three, 2 ones" = 121321 next number [iteration 3]: "1 one, 1 two, 1 one,...
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
Write a program in C that computes the area of a circle (Area = pi *...
Write a program in C that computes the area of a circle (Area = pi * r2) and the volume of a sphere (Volume = 4/3 * pi * r3). Both formulas use r which is the radius. Declare a float variable pi = 3.14159. Get the value of r from the keyboard and store it in a float variable. Display both the area of the circle and the volume of the sphere.
Write a C program to store the parameters of a circle on a 2D plane: the...
Write a C program to store the parameters of a circle on a 2D plane: the x and y coordinates of the center point and r, the radius. All three parameters are real (floating point) numbers. -Define a type to store the parameters of a circle. Write a function that receives the parameters of two circles as function parameters, and returns whether the two circles overlap or not. (Two circles overlap if the distance between their center points - computed...
Write c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
In java processing 3, write a program that draws a circle. The center of the circle...
In java processing 3, write a program that draws a circle. The center of the circle would be first point on the canvas where the mouse is pressed on it. While the mouse is pressed, the circle can be drawn by moving the mouse cursor farther than the first point that mouse was pressed (circle center). As soon as the code is run, a timer at the bottom of the canvas should start working. Also, the radius of the circle...
please write simple python 3 program with explanations and correct output Bilbo and problems on the...
please write simple python 3 program with explanations and correct output Bilbo and problems on the board Problem Statement Bilbo once reached his maths claws earlier than anyone else.He saw some N unique numbers greater than 0 written on the board.He thought of challenging his classmates when they come.So for each number i,he wrote the number before and after it on a paper slip.If it is the last number then the number after it is assumed to be 0.If it...
Write a C++ program to swap two numbers and show your output
Write a C++ program to swap two numbers and show your output
Write a C program with call to functions to produce the output given below. // the...
Write a C program with call to functions to produce the output given below. // the requirements are that there should be 5 files; intList.h, intList.c, hw3.h, hw3.c, and main.c. please only C and use Linked List. thank you. For the 5 different files, he wants it this way: 1) main.c This file just consists of the main() function, which only consists of the displayClassInfo() function call, and the runMenuHw3() function call. 2) intList.h This file would have the IntNode...
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT