Write a C main() program that keeps reading real numbers from standard input and
ID: 3537384 • Letter: W
Question
Write a C main() program that keeps reading real numbers from standard input and calls a MinMax() function to determine whether this number is a minimum or a maximum as compared to all the numbers already read. Then main() prints both minimum and maximum numbers to the standard output. Then main() continues reading another real number and this process repeats until EOF occurs. Note: %u2022 Program should print a proper message if there are no inputs. %u2022 Program should properly function if there is only one input. Write a C main() program that keeps reading real numbers from standard input and calls a MinMax() function to determine whether this number is a minimum or a maximum as compared to all the numbers already read. Then main() prints both minimum and maximum numbers to the standard output. Then main() continues reading another real number and this process repeats until EOF occurs. Note: %u2022 Program should print a proper message if there are no inputs. %u2022 Program should properly function if there is only one input.Explanation / Answer
#include <stdio.h>
void MinMax( int *min,int *max,int num)
{
if(num> *max) { *max = num; }
if(num < *min) { *min = num; }
}
int main()
{
int n;
if(!scanf("%d",&n))
{
printf("No Valid Input ");
}
else
{
int min=n;
int max=n;
while(scanf("%d",&n))
{
MinMax(&min,&max,n);
}
printf("Maximum: %d Minimum: %d ",max,min);
}
return 0;
}
Related 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.