Print sum of all digits of number using while loop

C program to read a number and calculate the sum of its digit.

Solution:

#include<stdio.h>
int main()
{
      int s=0,l;
      long n;
      printf("Enter Number : ");
      scanf("%ld",&n);
      while(n>0)
      {
            l=n%10;
            s=s+l;
            n=n/10;
      }
      printf("\nSum of All Digits : %d",s);
      return 0;
}


Output:

sum all digits of number