Sum of integers through command line arguments
#include<stdio.h> main(int argc,char **argv) { int r=0,sum=0,i,a[100]; for(i=1;i<argc;i++) { printf("argument values are %d\n",r=atoi(argv[i])); //r=atoi(argv[i]); sum=r+sum; } //printf("%d %d\n",sizeof(argv),sizeof(argc)); printf("sum=%d\n",sum); }OutPut:
madan@madan-Lenovo-G570:~/madan$ cc storage.c madan@madan-Lenovo-G570:~/madan$ ./a.out sum=0 madan@madan-Lenovo-G570:~/madan$ ./a.out 13 34 45 56 77 argument values are 13 argument values are 34 argument values are 45 argument values are 56 argument values are 77 sum=225