Wednesday 20 February 2013

Sum of digits


//Sum of digits
#include<stdio.h>
#include<math.h>
main()
{
int num,sum=0,digit;
printf("enter the num");
scanf("%d",&num);
x:while(num!=0)
{
digit=num%10;
num=num/10;
sum=sum+digit;
}
if(sum>9)
{
num=sum;
sum=0;
goto x;
}
printf("sum=%d",sum);
}

1 comment: