Created
January 17, 2010 09:15
-
-
Save jartur/279305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/* Define a constant */ | |
#define NUMBER 110771 | |
int ctoi(char c) | |
{ | |
return (int)c - 48; | |
} | |
int main(int argc, char** argv) | |
{ | |
int res = NUMBER * 9; | |
char as_string[11] = {0}; | |
int as_string_len = 0; | |
int i = 0; | |
printf("Multiply any number by 9 and add the numbers in the result.\nYou will get a 9.\n\n"); | |
printf("Number %d * 9 = %d\n", NUMBER, res); | |
while(res > 9) | |
{ | |
itoa(res, as_string, 10); | |
as_string_len = strlen(as_string); | |
res = 0; | |
for(i = 0; i < as_string_len; i++) | |
{ | |
res += ctoi(as_string[i]); | |
if(i < as_string_len-1) | |
{ | |
printf("%c+", as_string[i]); | |
} | |
else | |
{ | |
printf("%c\n", as_string[i]); | |
} | |
} | |
printf("Sum = %d\n", res); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment