Calculating Sum of two number


#include<stdio.h>

int  main(int argc,char *argv[])
{
    int i,j,sum=0;
    if(argc!=3)
        exit(1);
    i=atoi(argv[1]);
    j=atoi(argv[2]);
    sum=i+j;
    printf("%d",sum);
    return 0;
}

Output: ProgamName 5 6 ↵
                 11

Post a Comment

5 Comments

  1. Replies
    1. Sorry thats a mistake...I will correct it
      Thanks

      Delete
  2. what is significance of this line of code
    if(argc!=3)
    exit(1);
    please explain it.

    ReplyDelete
    Replies
    1. it is because while running through Command Line Argument you need to write
      programName num1 num2
      i.e., three parameters and if you don't pass 3 parameters then it will terminate execution

      Delete
  3. why we are taking exit(1) and not exit(0);

    ReplyDelete