Rewrite the following program so that it uses a while loop in language C. #inclu
ID: 673057 • Letter: R
Question
Rewrite the following program so that it uses a while loop in language C.
#include <stdio.h>
#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);
}
Explanation / Answer
#include <stdio.h>
#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);
slope = (y2 - y1) / (x2 - x1;
while(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);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.