The following C program describes the sum of individual digits of a given positive integer.
Example: 456 as 4+5+6 = 15
#include<stdio.h> #include<conio.h> 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