It's an stupid way but works
I'll be happy if someone could tell me a better way.
Thanks!
Code:
/* header files */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
/* Functions */
char subchar(char *string, int nIndex);
void check(int nNum);
int chatoi(char ch);
/* Global array, to hold the found numbers */
int nNums[10];
/* main */
int main(void)
{
int nIndex; /* for looping */
/* start looping */
for(nIndex = 100; nIndex <= 500; ++nIndex)
check(nIndex); /* see if it's the kind of number */
/* pause */
system("PAUSE");
/* return 0 */
return 0;
}
char subchar(char *string, int nIndex)
{
return string[nIndex]; /* return the right char */
}
void check(int num)
{
char ch1, ch2, ch3, str[3];
int n1, n2, n3, curr = 0;
itoa(num,str,10); /* transform integer into string */
ch1 = subchar(str,0); /* catch first char */
ch2 = subchar(str,1); /* second char */
ch3 = subchar(str,2); /* third char */
/* transform into numbers */
n1 = chatoi(ch1);
n2 = chatoi(ch2);
n3 = chatoi(ch3);
/* check if the 3rd power of the numbers added together
results in the num */
if(((n1 * n1 * n1) + (n2 * n2 * n2) + (n3 * n3 * n3)) == num)
printf("Yes! %d\n",num);
}
int chatoi(char ch)
{
return ch - 48;
}