This is a split board - You can return to the Split List for other boards.

Can someone help me with a program in C?

  • Topic Archived
You're browsing the GameFAQs Message Boards as a guest. Sign Up for free (or Log In if you already have an account) to be able to post messages, change how messages are displayed, and view media in posts.
  1. Boards
  2. PC
  3. Can someone help me with a program in C?

User Info: Glockass1

Glockass1
3 years ago#1
Using Dev-C++

Here's my code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int Number(int, int, int);

int main(int argc, char *argv[]) {
int x, y, z, N, M, result, sum ;
sum=0;
for (x = -99; x <= 99; x++){
for (y = x; y <= 99; y++){
for (z = y; z <= 99; z++){
result = Number(x, y, z);
printf("%d %d %d, %d\n",x,y,z,result) ;
if (result == 1){
printf("%d %d %d\n", x, y, z);
sum++;
}
}
}
}
printf("%d total combinations\n", sum);

return 0;
}

int Number(int x, int y , int z){
int a,b,c,d,e;
double d1;
d = a*a + b*b+ c*c;
d1= pow(d,1.0/3);
e=(int)d1;
if ((d1-e)== 0) {
printf("%7.5g \t", d1-e);
return 1;
}

else {
printf("%7.5g\n", d1-e );
return 0;
}


}

For some reason it doesn't work. Here is an example of the result:

http://i.imgur.com/IZURYvW.jpg

Why does it return 0 all the time?

Thanks for the help.

Check this image for better viewing:

http://i.imgur.com/UrQrriY.jpg
Steam ID: Glockass1
http://i.imgur.com/qsRb7.png http://i.imgur.com/PgA0Rlc.gif

User Info: neroAngelo

neroAngelo
3 years ago#2
Ask one of the thousands of C programming boards on the internet. Not a PC gaming board.
PSWii360U - This is how I triforce http://i.imgur.com/9qF9vGa.jpg
i7 920 @3.3GHz, 6GB DDR3, 7850 2GB

User Info: Ch3wy

Ch3wy
3 years ago#3
It's always returning 0 because d1-e does not equal 0.
How the hell can a octopus live outside of water anyways? This is so stupid. -Fade2black001

User Info: Glockass1

Glockass1
3 years ago#4
Ch3wy posted...
It's always returning 0 because d1-e does not equal 0.


I don't think that's it. Even for x=-2, y=0, z=2 it should be 1 but it's not.
Steam ID: Glockass1
http://i.imgur.com/qsRb7.png http://i.imgur.com/PgA0Rlc.gif

User Info: Ch3wy

Ch3wy
3 years ago#5
Have you tried using cbrt(d) instead of pow(d,1.0/3)?
How the hell can a octopus live outside of water anyways? This is so stupid. -Fade2black001

User Info: Ch3wy

Ch3wy
3 years ago#6
Wait a second you never even set the values for a, b, and c.
How the hell can a octopus live outside of water anyways? This is so stupid. -Fade2black001

User Info: popping4it

popping4it
3 years ago#7
Ch3wy posted...
Wait a second you never even set the values for a, b, and c.


ya that looks like the problem should be.

in line 31 d = x*x + y*y + z*z

or prior ...
a = x
b = y
c = z
whens mahvel?

User Info: Glockass1

Glockass1
3 years ago#8
popping4it posted...
Ch3wy posted...
Wait a second you never even set the values for a, b, and c.


ya that looks like the problem should be.

in line 31 d = x*x + y*y + z*z

or prior ...
a = x
b = y
c = z


lol that was the problem I think. I got confused because I thought they get values automatically. Thanks for the help. Also, is there a way to make the program faster? It takes a while to go through all the combinations.
Steam ID: Glockass1
http://i.imgur.com/qsRb7.png http://i.imgur.com/PgA0Rlc.gif

User Info: popping4it

popping4it
3 years ago#9
if the goal is to output all the combinations it has to run through x^3 no matter what. its likely the pow function is what ends up taking the most time.
whens mahvel?

User Info: Ch3wy

Ch3wy
3 years ago#10
There might be a chance that cbrt is faster than throwing a fraction into pow, but I'm not sure. Worth a shot.
How the hell can a octopus live outside of water anyways? This is so stupid. -Fade2black001
  1. Boards
  2. PC
  3. Can someone help me with a program in C?

Report Message

Terms of Use Violations:

Etiquette Issues:

Notes (optional; required for "Other"):
Add user to Ignore List after reporting

Topic Sticky

You are not allowed to request a sticky.

  • Topic Archived