Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote