Sunday, 22 October 2017

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

4 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

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...