This program accepts number n as input.Each and every digit of the number is considered to find the sum.For extracting the digit from the number,the number is divided by 10 and then remainder is added into sum.The number is then decremented by dividing it by 10.This process continous until the number gets decremented to 0.

#include < stdio.h > #include < conio.h > void main() { int n,sum; clrscr(); printf("\nEnter n : "); scanf("%d",&n); sum = 0; while ( n != 0 ) { sum = sum + n % 10; n = n / 10; } // while printf("\n SUM = %d",sum); } // main