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

Write a program in c language that finds a maximum of three numbers. Input consi

ID: 3641628 • Letter: W

Question

Write a program in c language that finds a maximum of three numbers. Input consists of the three numbers. Output should list the three numbers and display the largest of the three. Set up a user terminated loop. I am having trouble putting in the user terminated loop. The code I have works, but of course there is no do while loop in this code and that is what I am having trouble with.

I have;

#include<stdio.h>
#include<conio.h>
int main(void)
{
int a, b, c, greatest;
printf("Enter three numbers separated by spaces:");
scanf("%d %d %d", &a,&b,&c);
greatest = (a>b) ?((a>c) ? a : c) : ((b>c) ? b : c);
printf(" The greatest number is: %d", greatest);
system("PAUSE");
return 0;
}

Explanation / Answer

In order to use a loop, you should use an array:

*********

#include<stdio.h>
#include<conio.h>
int main(void)
{
int a[3];

int greatest;

int i = 0 ;


printf("Enter three numbers separated by spaces:");


scanf("%d %d %d", &a[0],&a[1],&a[2]);

greatest = a[0] ;


do {

    i = i+1 ;

    if (a[i] > greatest)

        greatest = a[i] ;

} while (i < 3) ;


printf(" The greatest number is: %d", greatest);
system("PAUSE");
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