Adding Digits in a number to reduce it to Single digit


This is a C program for recursively adding a number until it becomes a single digit.
This is a part of Mumbai University MCA College C program MCA Sem 1



Adding and Reducing number to Single Digit


#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=10,n1;
clrscr();
printf("Enter a number :-");
scanf("%d",&n);
while(sum>=10)
{
sum=0;
while(n!=0)
{
n1=n%10;
sum=sum+n1;
n=n/10;
}
n=sum;
}
printf("Sum of digits :- %d ",sum);
}



Intput :

Enter a number :- 179

Output :

Sum of digits :- 8

Flow Chart 

Adding Number till Single Digit



Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

No comments:

Post a Comment