C Coding Questions With Solutions


Question :

Write a C-program to find largest number among N numbers using command line arguments.

  
  
    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;
}