Question: Homework program C 1. In what ways are the initialization, repetition test, and update steps alike for a sentinel-controlled loop and an endfile-controlled loop? How
Homework program C
1. In what ways are the initialization, repetition test, and update steps alike for a sentinel-controlled loop and an endfile-controlled loop? How are they different?
2. Hand trace the program that follows given the following data:
4 2 8 4 1 4 2 1 9 3 3 1 -22 10 8 2 3 3 4 5
#include
#define SPECIAL_SLOPE 0.0
int main(void)
{
double slope, y2, y1, x2, x1;
printf("Enter 4 numbers separated by spaces.");
printf(" The last two numbers cannot be the ");
printf("same, but the program terminates if ");
printf("the first two are. ");
printf(" Enter four numbers> ");
scanf("%lf%lf%lf%lf", &y2, &y1, &x2, &x1);
for (slope = (y2 - y1) / (x2 - x1);
slope != SPECIAL_SLOPE;
slope = (y2 - y1) / (x2 - x1))
{
printf("Slope is %5.2f. ", slope);
printf(" Enter four more numbers> ");
scanf("%lf%lf%lf%lf", &y2, &y1, &x2, &x1);
}
return (0);
}
3. Rewrite the program segment that follows, using a for loop:
count = 0;
i = 0;
while (i < n) {
scanf("%d", &x);
if (x == i)
++count;
++i;
}
4. Rewrite this for loop heading, omitting any invalid semicolons
for (i = n;
i < max;
++i;);
5. Write a do-while loop that repeatedly prompts for and takes input until avalue in the range 0 through 15 inclusive is input. Include code that preventsthe loop from executing forever on input of a wrong data type.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
