Write a C program to find largest number among N numbers using command line arguments.
#include <stdio.h>
int main(int argc, char * argv[])
{
int i, n, large;
n = argc;
if(argc == 1)
exit(0);
large = atoi(argv[1]);
// Loop to store largest number to large
for(i = 2; i < n; i++)
{
if(large < atoi(argv[i]))
large = atoi(argv[i]);
}
//print statement should be according to Question
printf("Largest element = %d", large);
return 0;
}
#include <stdio.h>
int main(int argc, char * argv[])
{
int i, n, large;
n = argc;
if(argc == 1)
exit(0);
large = atoi(argv[1]);
// Loop to store largest number to large
for(i = 2; i < n; i++)
{
if(large < atoi(argv[i]))
large = atoi(argv[i]);
}
//print statement should be according to Question
printf("Largest element = %d", large);
return 0;
}
Output: ProgramName 5 11 23 43 65
Largest element = 65
0 Comments