Professional Documents
Culture Documents
Use a C loop construct (do, for, do while) to print the radius, circumference and area
for each circle. For this exercise it is ok to assume that the loop will have to be executed
3 times. The generalized structure for the loop is shown below
loop_counter = 0
begin loop
increment loop_counter
if statement for printing radius, circumference and area
if loop_counter >= 3
exit loop
end loop
Continue using the if else statement from your last assignment inside the loop.
However generalize the statement so that it will work for all radii. It should have the
following form:
// Calculate and print circumference and area for the circle.
printf("Circle %d radius: \t\t%6.2f\n", loop_counter, rad);
if (rad == 5)
{
printf("Circle %d circum: \t\t%6.2f\n", loop_counter, calcCircum(rad));
printf("Circle %d area:
\t\tNot Calculated\n\n", loop_counter);
}
else if (rad == 10)
{
printf("Circle %d circum: \t\tNot Calculated\n", loop_counter);
printf("Circle %d area:
\t\t%6.2f\n\n", loop_counter, calcArea(rad));
}
else
{
printf("Circle %d circum: \t\tNot Calculated\n", loop_counter);
printf("Circle %d area:
\t\tNot Calculated\n\n", loop_counter);
}
Please note you will only need to include one such if statement because it is generalized
to work for all loops.
Please note that the circles dont have to be listed in this order. For example, you could print
circle with radius 6.3 first.
Try several test runs with the order of the radii changed. Start with order 5, 10, and 6.3 then
revise the order and run it again. This will help verify that your if else statements work for all
radii.
Dont forget the following program head for all programs submitted for grading.
// Program Author:
// Student ID:
// Email Address:
// Name of Program:
// Program Due Date:
// Objective:
assignment
// Program Description:
// Honor Code:
//
else's
//
Enjoy!
Your name
xx000012345
xx@ltu.edu
Name of Program.c
MM-DD-YY
The Instructors description of the programming
The Students description of how the program works
I have neither given nor received unauthorized aid in
completing this work, nor have I presented someone
work as my own!