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);
}
No comments:
Post a Comment