C Program to add two numbers using command line Argument.

ADD USING COMMAND LINE ARGUMENTS. 


#include<stdio.h>

#include<stdlib.h>

int main(int argc,char *argv[])

{

    int i, sum = 0;

    if (argc < 3)

    {

        printf("<--Please Enter at least 3 argument to execute this Proggram-->");

        exit(0);

    }

    else

    {

        for(i = 0 ; i < argc ; i++)

        {

            sum = sum + atoi(argv[i]);

        }

        printf("Addition of entered arguments is = %d",sum);

    }

    return 0;

}


INPUT && OUTPUT






  In the command line argument program you have to run your  program  as,

 " Program name  Argument1,Argument2....(Argument list)". 


Post a Comment

0 Comments