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();
}
▶ RUN

Output/ Explanation:

OUTPUT:

Enter a Number :4687

Sum of Digits till a single digit

4687

25

7

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad