Even and Odd digits Sum in C using Command line


#include<stdio.h>
int main(int argc,char *argv[]){
int sum1=0;
int sum2=0;
//int semaphore=0;
int n=atoi(argv[1]);
int num=n;
int temp;
int i=0;
int f=0;
while(n>0){
temp=n%10;
if(f==0){
sum1+=temp;
f=1;
}
else{
sum2+=temp;
f=0;
}
n=n/10;
i++;
}
if(i%2==0){
printf("Odd digits sum of %d is %d\n",num,sum2);
printf("Even digits sum of %d is %d\n",num,sum1);
}
else{
printf("Odd digits sum of %d is %d\n",num,sum1);
printf("Even digits sum of %d is %d\n",num,sum2);
}
return 0;
}

Comments