Hey there! I'm new to the C language, don't need to tell me I'm a newbie, I know I suck. >.>
I'm currently taking a C introductory course and I'm having some trouble with some of these assignments because I don't really have any coding precedence. I'd really appreciate some help. = )
This first assignment is to find all numbers that follow the cube rule from 100-999.
The cube rule being, the first digit cubed added to the second digit cube added to the third digit cubed equals the number.
For example of the cube rule, the number 153 is 1^3 + 5^3 + 3^3 = 153
The results expected to be printed are -
153 has the cube property. (1 + 125 + 27)370 has the cube property. (27 + 343 + 0)371 has the cube property. (27 + 343 + 1)407 has the cube property. (64 + 0 + 343)
This is what I have so far. I've tried to compile it and I know it has errors, though I'm not sure exactly how to fix it. Any help is appreciated! = )
Code:
#include <stdio.h>
int main(void)
{
int a, b, c, atrip, btrip, ctrip, cubecheck;
for (cubecheck = 100; cubecheck <= 999; cubecheck++)
a = (cubecheck % 10);
c = (cubecheck / 100);
b = ((cubecheck - (c*100 + a) )/ 10);
atrip = (a*a*a);
btrip = (b*b*b);
ctrip = (c*c*c);
if(atrip + btrip + ctrip == cubecheck);
prinf("%i has the cube property. (%i + %i + %i )\n", cubecheck, atrip, btrip, ctrip);
}
return 0;
}