Tuesday, 1 January 2019

Filled Under:

Find sum of digits of a number[c programming examples with output]

C programming examples with output

Find sum of digits of a number

Program

#include<stdio.h>
#include<conio.h>
main()
{
       int a,b;
       long n;
       clrscr();
       printf("Enter any numbr: ");
       scanf("%ld",&n);
       b=0;
       while(n>0)
       {
             a=n%10;
             b=b+a;
             n=n/10;
        }
        printf("The sum of digits is %d",b);
        getch();
}

Output

Enter any number: 45632
The sum of digits is 20

0 komentar:

Post a Comment