If a five digit number is input through the keyboard, write a program in C to calculate the sum of its digits

If a five digit number is input through the keyboard, write a program in C to calculate the sum of its digits.
 
            #include <stdio.h>
            #include <conio.h>
            void main()
            {
                        int a,b,c,d,e,f,g;
                        clrscr();           
                        printf("Enter a five digit number : ");
                        scanf("%d", &a);
                        b=a/10000;
                        c=a%10000/1000;
                        d=a%10000%1000/100;
                        e=a%10000%1000%100/10;
                        f=a%10000%1000%100%10;
                        g=b+c+d+e+f;
                        printf("\n\nSum of digits of number ; %d", g);
                        getch();
            }
                 


Post a Comment