# Print from 1 to 10 without using a loop

• 12-22-2003
Guti14
Print from 1 to 10 without using a loop
Hi,

I can't use loops for this. Will I have to declare each number from 1 to 10 if I wish to print the square and cube of 1 until 10??

Thanks
Code:

```int main(int argc, char* argv[]) {   int number;   cout << "Enter a number(s), and you will receive the square and cube of" <<   " that number: " << endl;   cin >> number;   cout << "number\t" << "square\t" << "cube" << endl;   cout << number << "\t";   number = number * number;   cout << number << "\t";   number = number * number * number;   cout << number;   getch();   return 0; }```
• 12-22-2003
Dante Shamest
How about a recursive function?
• 12-22-2003
Guti14
I wish I could, but I am only at the beginning of my big book and haven't covered that yet. Only thing Iv'e used it if/else.
So will I have to declare all ten numbers??
• 12-22-2003
glUser3f
I really think that such questions are pointless, loops are there to use them, insead of forcing some technique upon the user, a book should give the user a problem to solve, and not ask for some way to solve it.

/offtopic
• 12-22-2003
axon
Quote:

Originally posted by glUser3f
I really think that such questions are pointless, loops are there to use them, insead of forcing some technique upon the user, a book should give the user a problem to solve, and not ask for some way to solve it.

/offtopic

they are not useless, because the object of real computer science is not to learn the syntax of a language but to learn how to solve problems. I had to make a nine morris games once without using arrays or globals!
• 12-23-2003
VirtualAce
I don't think exercises like this teach anything. They only serve to confuse the student - just look at how many questions we have from said 'confused students' on this board.

Give em a real programming assignment. This is like asking them to build a house, but you can't use nails, wood, saws, or any other wood working tool that was designed for building houses.

Not sure what you mean by square and cube of 1 to 10. Do you mean each number from 1 to 10 squared, or do you mean 1 squared, 2 cubed, 3 ....and so on?
• 12-23-2003
WDT
In progrqamming logic, problems of this nature are solvable by either recursion or looping sensibly; the only other way would be for you to go with your correctly guessed solution if either of the other two option is not opened to you.
Agree with axon, problems like this are there for students to grasp conceptual problems and solutions, Man didn't first build a house using bricks and nails, I believe he had to grasp the concept of wwhat a shelter is first before he invented those things. :)
• 12-23-2003
VirtualAce
Well I've seen the results of the 'concepts' they teach firsthand. This is convoluted crap no one will/should ever attempt.

I've seen some very dumb assignments on here and I'll just add this one to my list.
• 12-23-2003
Salem
The only thing in a loop here is you asking how to do things without loops
What's next - write an OS without loops?

I bet your teacher is about 1/2 page in front of you in the book, and has yet to figure out what loops are for themselves.
• 12-23-2003
VirtualAce
Quote:

The only thing in a loop here is you asking how to do things without loops
What's next - write an OS without loops?

I bet your teacher is about 1/2 page in front of you in the book, and has yet to figure out what loops are for themselves.
:D
• 12-23-2003
Cat
Quote:

Originally posted by axon
they are not useless, because the object of real computer science is not to learn the syntax of a language but to learn how to solve problems. I had to make a nine morris games once without using arrays or globals!
Yes, but learning to solve problems without being allowed to use the obviously best option is, well, foolish.

If they want to challenge students, give them a more complicated real-world problem, without constraints, rather than give a problem artificially made more complicated by the addition of insane rules.

I have no problem with giving people realistic restrictions (e.g. restrictions on computation time, memory usage, etc.) but removing the obviously optimal solution, then trying to make people solve it, seems a bit pedantic.
• 12-23-2003
Iamien
I figure by now you have figured soem kidn of solution, but here an example

Code:

```#include <iostream> void NoLoop(int number) { if (number >= 0) { std::cout<<number<<endl; NoLoop(number - 1); } return; } int main() { NoLoop(10); return 0; }```