### Loop (for) expression problem

So in school we just learned the for command and then our teacher made us do some exercises. One exercise involved making a program that outputted this:

1
4
9
16
25
36
49
64
81
100

For the whole 20 or so minutes given to us to make the 4 for programs, this one had me completely flustered. I thought and I thought how to do it and nothing I thought of worked. T_T My smart classmates couldn't think of an expression to fit it either. So it involves perfect squares from 1 to 10. What should be my expressions?
 So it involves perfect squares from 1 to 10.

So you already know what you want!

 ``12`` ``````for (int i=1; i <= 10; ++i) std::cout << i * i << std::endl;``````

this would be easier if you have a for loop inside another for loop, something like :

 ``1234567`` `````` for( int i = 1; i < 101; i++ ) { for( int j = 1; j < 101; j++ ) { if( THIS_IS_FOR_YOU_TO_DETERMINE ) { cout << i << endl; } } }``````

Edit use @catfish's method, i didn't think of that simple way :)), sorry i'm not good at math,

i kinda feel embarrassed
Last edited on
YUSH!!! Thanks, Catfish! It worked!
Thanks for the answer also, Shadow Fiend. :3 Forgot to mention that we were only allowed to use ONE loop command.
Topic archived. No new replies allowed.