
#1
Oct207, 12:12 PM

P: 43

Hi,
I am trying to write a program on a C compiler and Im not too sure how to do it. The question asks to write a full program to calculate the squares and cubes of the numbers from 0 to 10, which uses tabs (\t) to illustrate the data in the table. Click on the uploaded document to view the question. "Ques Example.jpg" Also I have given an example of a square root I have calculated for a number in document, "Example of.jpg" However Im not too sure which instructions are needed to show the information in a table. Please help, thanks very much ! 



#2
Oct207, 01:05 PM

Mentor
P: 14,477

Some questions:




#3
Oct207, 01:54 PM

P: 43

Well I only know how to add, subtract and multiply groups of numbers together and find the average of them.
I know how to print instructions on the screen, for instance, phrases like "Enter two integers", "Answer/sum =" Thats about it 



#4
Oct207, 02:12 PM

Mentor
P: 14,477

C, compiler  write a table from a program
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".
Have you been taught about looping yet? 



#5
Oct207, 03:12 PM

P: 43

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. I think we havent been taught looping yet? Any example of this? 



#6
Oct207, 03:59 PM

P: 43

Hang on,
Do I just type the correct values under each header instead, without it actually being a flowing program. 



#7
Oct207, 05:09 PM

Mentor
P: 14,477

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. 



#8
Oct207, 05:15 PM

P: 43

haha.
Yes thats right. Um... I have only really mannaged to seperate the three columns. But when I type in the numbers it wont show properly, as Im missing out a large part of the program. 



#9
Oct307, 10:09 PM

P: 181

Can you post your code? You can post your code on rafb.net/paste  you will be provided with a link  please paste that here.
Also remember to make sure "C" formatting is on when you're on that website. 



#10
Oct807, 06:50 PM

P: 43

Yes I have it here now.
It automaticaly calculates the square and cube roots of the first number typed in. However the first number you type appears in the table as well and will not let me type in more numbers for the next line. A loop in the program is needed here ???? http://rafb.net/p/CBphkL43.html 



#11
Oct807, 09:53 PM

P: 210

yes a loop is needed here.
EDIT sorry I thought you didnt want to input numbers to appear for some reason. Pay attention to the carriage return that will make your table look bad after scanf. 



#12
Oct1007, 03:24 PM

P: 43

Okay so what is the carriage return?
Would that be the last part of the program to finish it? http://rafb.net/p/sCyV4l30.nln.html 



#13
Oct1107, 12:31 AM

P: 9

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.




#14
Oct1107, 07:26 AM

P: 43

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. ??? 



#15
Oct1107, 09:21 AM

P: 210

++ is to increment variable idx so after it deals with one number say 3 in the loop and adds it to the table, it will move to 4 and so on.
idx++ means idx=idx+1. If this was not put then you will get stuck in an infinite loop and have a program crash. 



#16
Oct1107, 11:41 AM

P: 43

Ah cool, I understand now.
Thanks once again ! 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? 



#17
Oct1107, 01:21 PM

P: 43

I have another question and managed to answer it, as it seems like it is working correctly.
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? Here it is: http://rafb.net/p/uKmqqQ58.nln.html 



#18
Oct1507, 02:06 AM

P: 9

"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... here's a quick example



Register to reply 
Related Discussions  
Help! need to write fortran program  Programming & Computer Science  8  
Write a program to simluate multi object  Advanced Physics Homework  7  
SML compiler?  Programming & Computer Science  1  
Program to write neat equations and problems  General Math  4  
robot uses four servos to walk  Computing & Technology  1 