Thursday, 26 October 2017

Sum of Digits of Number

#include<stdio.h>
int main(int argc,char *argv[])
{
int dig,sum=0,num;
if(argc!=2)
exit(1);
num=atoi(argv[1]);
while(num!=0)
{
dig=num%10;
num=num/10;
sum=sum+dig;
}
printf("Sum of digits %d",sum);
return 0;
}
Contributed by Priti Lohia

No comments:

Post a Comment

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...