Calculate Sum of digits of the entered number

#include<stdio.h>
#include<conio.h>
int main()
{
int rem,sum=0,n;
clrscr();
printf("Enter any number");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("Sum of digits of the entered number is %d",sum);
getch();
return 0;
}

0 comments:

Post a Comment