![]() |
|
#1
|
|||
|
|||
times table programi need help making a program that makes the times tables appear after you enter a number. for e.g if you enter 2 it comes up with
1*2=2 2*2=4 etc all way down to 12*2=24 i need this to happen from when you type in any number from 1 - 12 and it needs to give the times table like above for any numbers. any help will be appriciated jay |
|
#2
|
||||
|
||||
Re: times table programSounds Like Homework
|
|
#3
|
||||
|
||||
Re: times table programHello Jay,
Welcome to GIDForums. To print the tables, you need a loop. Consider that the number is x. Then, the first line should print: 1 * x = answer 2 * x = answer and so on. For example, consider that the number is 2 as you said. Then, : 1 * 2 = 2; 2 * 2 = 4; What can we do about this? We can have a variable i, that varies from 1 to 12. If x is the input, then the psuedo code looks like: Quote:
But how to code this in program? Use the for loop, which you can use for this program. First get the input from the user.(I hope you know how to do this Then, in a loop, like this: CPP / C++ / C Code:
At the first iteration, i is 1. After the end of the iteration, the value of i is incremented by 1. This is indicated by the "i++" statement. And the loop goes on.. When the value of i becomes greater than 12, the loop exits. So, you have to print the Values inside the loop. In C, you can use the printf statement. For example, like this: CPP / C++ / C Code:
So, the first %d corresponds to i, second %d corresponds to x, and the third %d corresponds to i*x. Now, Are you ready for another challenge? Print All the tables from 1 to 10. (Hint: Use Another loop.) Regards, Paramesh. __________________
Don't walk in front of me, I may not follow. Don't walk behind me, I may not lead. Just walk beside me and be my friend. |
|
#4
|
|||
|
|||
Re: times table programOk cheers anyway i do get what you all said, and yes it was home work
|
|
#5
|
||||
|
||||
Re: times table programWelcome to GID
Quote:
For a newbie who is afraid of the library But I see Paramesh did an excelent job (as always - Keep them coming, Paramesh) in giving you more then just code. Kobi. __________________
It's actually a one time thing (it just happens alot). |
Recent GIDBlog
Welcome to Baghdad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| creating a file in [c] | i hate c | C Programming Language | 15 | 21-Nov-2005 12:52 |
| Type casts ? | kai85 | C++ Forum | 12 | 23-Jun-2005 12:04 |
| [TUTORIAL] Calling an external program in C (Linux) | dsmith | C Programming Language | 4 | 22-Apr-2005 13:30 |
| Help with simple math table program (was a SIMPLE program) | Bubba | C Programming Language | 3 | 09-Mar-2005 12:40 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 07:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The