Program to add digits of a number
This is a program to a 5 digit number from user and output the sum of digits. The program works for some numbers. See the output image

    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    
    long sumDigits(long n)
    {
     long sum = 0;
     int rem;
    
     if(n>0)
     {
       rem = n%10;
       sum = sumDigits(n/10) + rem;
     }
    
     return sum;
    }
    
    
    
    void main()
    {
     long num,digits,sum;
    
     clrscr();
     printf("Enter a number: ");
    
     start_again:
     scanf("%ld", &num);
    
     digits = log10(num) + 1;
     if(digits>5)
      {
        printf("The number you have entered has more than 5 digits. \nPlease enter a new number \n");
        goto start_again;
      }
    
     sum = sumDigits(num);
     printf("\nSum of digits = %ld", sum);
    
     getch();
    }

This is the output I get:

![enter image description here][1]


  [1]: http://i.stack.imgur.com/zYB29.png
Program to add digits of a number
===

This is a program to a 5 digit number from user and output the sum of digits. The program works for some numbers. See the output image

    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    
    long sumDigits(long n)
    {
     long sum = 0;
     int rem;
    
     if(n>0)
     {
       rem = n%10;
       sum = sumDigits(n/10) + rem;
     }
    
     return sum;
    }
    
    
    
    void main()
    {
     long num,digits,sum;
    
     clrscr();
     printf("Enter a number: ");
    
     start_again:
     scanf("%ld", &num);
    
     digits = log10(num) + 1;
     if(digits>5)
      {
        printf("The number you have entered has more than 5 digits. \nPlease enter a new number \n");
        goto start_again;
      }
    
     sum = sumDigits(num);
     printf("\nSum of digits = %ld", sum);
    
     getch();
    }

This is the output I get:

![enter image description here][1]


  [1]: http://i.stack.imgur.com/zYB29.png