source file name:  While6.C 

void main()

{

long n;

int d,sum=0;

clrscr();

printf(" enter any no: \n");

scanf("%ld",&n);

while(n>0)

{

d=n%10;

sum=sum+d;

n=n/10;

}

printf("\n  sum of digit= %d ",sum);

getch();

}

output:

1. enter any no: 12345

sum of digit=15 

2. enter any no: 1234567891

sum of digit=46