Sunday, August 7, 2011

Sum of individual digits of a number


#include<stdio.h>

void main()
{
int num,rem,sum=0;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
while(num>0)
   {
   rem=num%10;
   sum+=rem;
   num/=10;
   }
printf("\nSum of individual digits is %d ",sum);
getch();
}

0 comments:

Post a Comment