How to Calculate SUM Digits Of a Number

//code

#include<stdio.h>
main()
{
int n,sum=0;
printf("Enter no \n");
scanf("%d",&n);
while(n>0)
{
sum=sum+n%10;
n=n/10;
}
printf("Sum of no is=%d\n",sum);

}

No comments:

Post a Comment