Program to add individual digits of a number

#include<stdio.h>
#include<conio.h>

void main()
{
long int a,n,sum=0;
clrscr();

printf(“enter any number”);
scanf(“%lld”,&n);

while(n>0)
{
a=n%10;    // storing the remainder
sum=sum+a;
n=n/10;
}
printf(“%lld”,sum);
getch();
}

Output:

individual digit of a number

Leave a Reply