Source Code:
#include<stdio.h>
#include<stdlib.h>
void main(int argc , char * argv[])
{
int i,sum=0;
if(argc!=3)
{
printf("you have forgot to type numbers.");
exit(1);
}
printf("The sum is : ");
for(i=1;i<argc;i++)
sum = sum + atoi(argv[i]);
printf("%d",sum);
}
Output:
D:\D INSTALL\TDM-GCC-32\Programs>add 2 4
The sum is : 6
D:\D INSTALL\TDM-GCC-32\Programs>add 5 4
The sum is : 9
Check Here:
#include<stdio.h>
#include<stdlib.h>
void main(int argc , char * argv[])
{
int i,sum=0;
if(argc!=3)
{
printf("you have forgot to type numbers.");
exit(1);
}
printf("The sum is : ");
for(i=1;i<argc;i++)
sum = sum + atoi(argv[i]);
printf("%d",sum);
}
Output:
D:\D INSTALL\TDM-GCC-32\Programs>add 2 4
The sum is : 6
D:\D INSTALL\TDM-GCC-32\Programs>add 5 4
The sum is : 9
Check Here:
- How to Use Command Line Arguments in C
Thanks and regards,
Tech Bird
Comments