C program to find Sum of Digits of a Positive Integer Number

include

main()
{
int r,n,m,sum;
//clrscr();
printf(“Enter a positive Integer :”);
scanf(“%d”,&n);
if(n<0)
printf(“The given number is not +ve Integer”);
else
{
sum=0;
m=n;
while(m!=0)
{
r=m%10;
sum+=r;
m/=10;
}
printf(“The given number =%d\n”,n);
printf(“Sum of digits of the given number is:%d”,sum);
}
}
You can find the flow chart for the above code here.

OUTPUT:

Enter a positive Integer :456
The given number =456
Sum of digits of the given number is:15

Leave a Reply

Your email address will not be published. Required fields are marked *