Write a program to read an integer number and keep on adding the digits till
we get a number with a single digit. For example, 7976 yields an output of 2
(7976 - - t 29 - - t 11 - - t 2)
.
For this, your main()
function must call the function sumdigits(0)
to solve
the problem, and then print the final result.
I have solved this problem and the logic is correct, I am not getting any output When i give my input it just move to next line.
#include <stdio.h>
sumdigits(int x)
{
int n = x;
int y = 0;
while(n>0) {
y = y + n % 10;
n = n / 10;
}
return y;
}
int main(void)
{
int a;
scanf("%d",&a);
while(a>10) {
a=sumdigits(a);
}
printf("%d",a);
}