C Program to Find Sum of Individual Digits of a Positive Integer Number

The following C program describes the sum of individual digits of a given positive integer. 

Example: 456 as 4+5+6 = 15

include

include

void main()
{
int n,sum=0;
printf(“enter a +ve integer”); // enter a integer value
scanf(“%d”,&n);
while(n>0) // checks the condition
{
sum=sum+n%10; // sum + remainder value
n=n/10;

}
printf("sum of individual digits of a positive integer is %d",sum);  // prints the sum of individual digits
getch();

}

OUTPUT:

enter a +ve integer456
sum of individual digits of a positive integer is 15

Leave a Reply

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