Sunday, 5 April 2015

C Program to print sum of digits of given number.

#include<stdio.h>
#include<conio.h>
main()
{
          int n,sum=0,r;
          clrscr();
          printf("Enter the number\n");
          scanf("%d",&n);
          while(n>0)
          {
                    r=n%10;
                   sum=sum+r;
                   n=n/10;
          }
          printf("\nSum of digits is : %d",sum);

No comments:

Post a Comment