Sum of Digits Program in C programming

 

C program to find sum of digit  of a number

    1. #include<stdio.h>
    2. int main()
    3. {
    4.    int n;
    5.    int sum=0;
    6.    int m;
    7.    printf("Enter number:\n");
    8.    scanf("%d",&n);
    9.             while(n>0)
    10.                  {
    11.                   m = n%10;
    12.                   sum = sum+m;
    13.                   n = n/10;
    14.                   }
    15.    printf("Sum is = %d\n",sum);
    16.    return 0;
    17. }

Post a Comment

0 Comments