Mathematically speaking, it's pretty awesome. I would consider a recursive function only you wrote that you have not learned functions yet, so...
perhaps...whether this is optimum or some better program can be written.
Code:#include <stdio.h> int main() { int num, r, sum=0; printf("Enter a no: "); scanf("%d",&num); while( num != 0 ) { r = num % 10; num /= 10; sum += r; if ((num == 0) && (sum > 9)) { num = sum; sum = 0; }; }; printf("the sum of digits is %d",sum); return 0; };