Write the program to find or count the digits sum.

#include<stdio.h>
#include<conio.h>
void main()
{
    int num, a, n;
    int sum=0;
    printf("\nEnter the values of number less than 32767: ");
    scanf("%d", &num);
    /* last digit extracted as remainder */
    a=num%10;
    n=num/10;
    sum=sum+a;
    /* fourth digit extracted as remainder */
    a=n%10;
    n=n/10;
    sum=sum+a;
    /* third digit extracted as remainder */
    a=n%10;
    n=n/10;
    sum=sum+a;
    /* second digit extracted as remainder */
    a=n%10;
    n=n/10;
    sum=sum+a;
    /* First digit extracted as remainder */
    a=n%10;
    sum=sum+a;
    printf("\nThe sum of enter digit is: ");
    printf("\n%d",sum);
    getch();
}


Sample output:

Post a Comment

Previous Post Next Post