Staff: Mentor

You have to compute the square and cube of a number. You already computed the cube. Print the data using printf, one line at a time. If formatted correctly you will get the desired pretty table. You already used "\n" to generate an end of line. Tab is just another special character: "\t" instead of "\n".

How do you prevent the numbers from showing up.
Shouldnt it be so that when you type in the number "3" under the number title (for example) all of its possible combinations will show up such as "9" and "27" under the squared and cubed titles.

Staff: Mentor

Looping in 'c' is done with the for or while statement.

I think you are supposed to do the calculations. You could easily write a one statement program that produces the table (just print the table), but that would violate the spirit of the assignment and would probably result in some point deductions.

This code is fairly simple as long as your know about the math header and how to use loops. I commented this code fairly well, so you shouldn't have any trouble understanding. Make sure you know what's going on in every line though. This is some VERY BASIC stuff that is extremely vital in computer programming. So it's important for you to learn about this stuff now, rather then later.

Thanks very much for your help!
I have been changing parts in the program to get a better understanding of how it works.

I see that you added in maths header and how the "<= 10" part is there to decide on how many numbers (increasing from 0) are required in the table, as the numbers must be less than or equal to 10. Also the word "double" is an instuction that must be enterd just like "printf, scanf, int" e.t.c for it to be performed.

And then what ever you replace "n" with in "A = pow(x, n);" will determine the power in the coloumn labeld as "A".
The ".0f" after the answer given by "%d" is needed for the answers to appear in that coloumn.
"getchar();" is needed for the black screen to appear on the screen until the user closes it.

But Im not sure why the "++" part is needed after the "<= 10; ix" bit.
???

Also I tried running the program without the "void" in between the brackets "int main( )" and it seemed to work fine, what is the reason for this?

Hey sorry for the late response.

"int main(void)" is just a c99 standard which means it's universally accepted by any compiler...

although almost every compiler accepts "int main()" since void is assumed because no command line arguments are needed..

"int main(int argc, char **argv)" is also the appropriate c99 standard way of using command line arguments...

Th program below is designed to state whether the integer entered is an Even or Odd number. I just thought there might be a better and more proffesional way of writting it?

The link you posted doesn't work. But THE BEST way to check for even and odd numbers without going outside the C standard library is to divide by 2 using modulo... module is just "%" and it returns the remainder... so odd will return 1 and even will be 0..

Hey NoUse, why is it that when you add .0, or even . in front of f in the 2nd to last printf statement it removes the 0's after the decimal place for each number? I noticed that if you take out the .0, the output will be 0.000000, 1.000000, etc. And if you add the . or .0 before f it will just print 0, 1, etc. Also, I notcied that if you use int, instead of double the program just outputs all 0's, why is double needed? I know double is for double precision and that's it. Thanks!
-Matt