Simplify the following program if possible: This program finds the largest and s
ID: 3639265 • Letter: S
Question
Simplify the following program if possible:This program finds the largest and smallest of four integers entered by the user:
Enter four integers: 21 43 10 35
Largest: 43
Smallest: 10
#include <stdio.h>
int main(void)
{
int i,num,c=0;
int largest;
int smallest;
printf(" Enter four integers:");
for(i=0;i<4;i++)
{
scanf("%d",&num);
if(c==0)
{
largest=num;
smallest=num;
c++;
}
if(num>largest)
largest=num;
if(num<smallest)
smallest=num;
}
printf(" Largest: %d",largest);
printf(" Smallest:%d",smallest);
return 0;
}
Explanation / Answer
This program is pretty much basic. However the c variable is unneccesary #include int main(void) { int i,num; int largest=0; int smallest=0; printf(" Enter four integers:"); for(i=0;ilargest) largest=num; if(numRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.