2/21/2009

C Program To Find The Sum Of The Digits Of A Given Number



/*C Program To Find The Sum Of The Digits Of A Given Number*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,q=0,sum=0;
    printf("Enter the number: \n");
        scanf("%d",&n);
     while(n!=0){
        q=n%10;
        n=n/10;
        sum=sum+q;
     }

      printf("Sum of the digits of a given number is = %d\n",sum);
    return 0;
}
Out Put:
Enter the number:
12345
Sum of the digits of a given number is = 15

No comments:

Post a Comment