sum of digit of given number

/*sum of digit of given number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int number,sum=0,r;
clrscr();
printf("enter the number\n");
scanf("%d",&number);
do
{
r=number%10;
sum=sum+r;
number=number/10;
}
while(number!=0);
printf("sum of digit is=%d\n",sum);
getch();
}



OUTPUT
enter the number
123
sum of digit is=6
Related Posts Plugin for WordPress, Blogger...