C Programs

Write a C program to print sum of digits of given number?


/* C Program that prints sum of digits of given number */
#include <stdio.h>
#include<conio.h>
int main() {
    int sum=0,lastDigit,number;
    clrscr();
    printf("Enter the Number : ");
    scanf("%d",&number);
    while (number > 0) {
          lastDigit = number % 10;
          sum += lastDigit;
          number /= 10;
    }
    printf("Sum of digits : %d \n",sum);
    getch();
    return 0;
}
www.000webhost.com