/*Serial No.48 [swami19.cpp]*/
#include<conio.h>
void main()
{
long int n,rem,sum=0;
clrscr();
printf("Enter the number==>");
scanf("%ld",&n);
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
printf("%ld",sum);
getch();
}
/*Program works good upto 9-digit.*/
#include<stdio.h>#include<conio.h>
void main()
{
long int n,rem,sum=0;
clrscr();
printf("Enter the number==>");
scanf("%ld",&n);
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
printf("%ld",sum);
getch();
}
No comments:
Post a Comment
If you have any doubt, feel free to ask...