Friday, September 12, 2008

SUM OF THE DIGITS OF A NUMBER program in c language


void main()
{
  int num,sum=0,r;
  clrscr();
  printf("\nEnter a number:");
  scanf("%d",&num);
  while(num)
  {
            r=num%10;
            num=num/10;
            sum=sum+r;
  }
   printf("sum=%d",sum);
  getch();
}

No comments:

Post a Comment

Thanks to given comments.......

My Blog List