Skip to content

Instantly share code, notes, and snippets.

@fkztw
Created April 29, 2013 20:46
Show Gist options
  • Save fkztw/d6b0cb7bf5486b4659fa to your computer and use it in GitHub Desktop.
Save fkztw/d6b0cb7bf5486b4659fa to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cstring>
int main (void)
{
char s[11];
while ( scanf("%s", s) != EOF && s[0] != '0' )
{
while ( strlen(s) != 1 )
{
int F = 0;
for ( int i = 0; i < (int)strlen(s); i++ )
{
F += s[i] - '0';
}
memset(s, '\0', 11);
sprintf(s, "%d", F);
}
printf("%s\n", s);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment