SUM OF DIGITS UNTIL IT CHANGES TO A SINGLE NUMBER
Consider the following I/O samples.
SAMPLE INPUT : 9863 == 9+8+6+3=26 == 2+6=8
SAMPLE OUTPUT: 8
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%9 == 0)
printf("9");
else
printf("%d",n%9);
return 0;
}
OUTPUT:
The given source code in C program is short and simple to understand. The source code is well tested in DEV-C++ and is completely error free.
If you have any feedback about this article and want to improve this, please comment in the comment section.
C PROGRAM:
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
if(n%9 == 0)
printf("9");
else
printf("%d",n%9);
return 0;
}
If you have any feedback about this article and want to improve this, please comment in the comment section.
Comments
Post a Comment