Programming Examples

Accept a number and find sum of its individual digits repeatedly till the result is a single digit.


Write a program to accept a number and find sum of its individual digits repeatedly till the result is a single digit.

Solution

# include <stdio.h>
void main()
{
int n,s=0;
clrscr();
printf(“\n Enter a Number :”);
scanf(“%d”,&n);
printf(“\n Sum of Digits till a single digit\n %d”,n);
for(; n!=0 ;)
{
 s=s+n%10;
 n=n/10;
 if(n==0 && s>9)
 {printf(“\n %2d”,s);
 n=s;
 s=0;
 }
}
printf(“\n %2d”,s);
getch();
}
Output

OUTPUT:

Enter a Number :4687

Sum of Digits till a single digit

4687

25

7

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad