Name this program limits c The program looks at all the com

Name this program limits. c - The program looks at all the command-line arguments, which all represent valid integers, and prints the largest and smallest values seen on the command line. There will always be at least one integer entered on the command line. Sample executions are shown below: ./a.out 10 20 30 25 15 5 The largest number is 30 and the smallest number is 5 ./a.out 99 55 11 -6 600 32 The largest number is 600 and the smallest number is -6

Solution

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int i,largest,smallest,count;
largest=0;
smallest=999;
int array[10];
if (argc < 2)
{
printf(\"Not enough arguments entered\ \");
exit(1);
}
  
  
for(i = 0; i < argc; i++)
array[i] = atoi(argv[i]);
  
count=i;
for(i=0;i<=count;i++)
{
if(array[i]>largest)
largest=array[i];
if(array[i]<smallest)
smallest=array[i];
  
}
printf(\"\ Smallest Number=%d\",smallest);
printf(\"\ Largest Number=%d\",largest);
  

return 0;
}

output:

sh-4.3$ main 89 67 -56 45 88

                                                                                                                                                                                

Smallest Number=-56              

Largest Number=89   

 Name this program limits. c - The program looks at all the command-line arguments, which all represent valid integers, and prints the largest and smallest valu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site