adding a second variable into the first...
Nov 3, 2008 at 5:49am UTC
hello...i need to output "1 4 9 16 25 36 49 64 81 100 121 144"
i can see the pattern as x + 2 (3 5 7 9...)
however i am having trouble nesting a loop to get that variable to function
where do i need to define the 'h' in my code and how should i format that?
thanks in advance this has taken me hours of trial and error.
cheers~j
--------------------------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
void loop_5(void )
{
int i;
int h;
for (i = 1; i <= 144; i = i + h)
//(h = 3; h = h + 2)
{
// for(h = 3; h <= 200, h = h + 2)
printf("%d " , i);
}
printf("\n\n" );//spaces after outputs
}
Last edited on Nov 3, 2008 at 7:15am UTC
Nov 3, 2008 at 7:34am UTC
actually i think my question is better as 'how do i count up by 1 number squaring it.....1*1 then 2*2....'
if that helps...but i am still stuck
i get 1 4 25 end
Nov 3, 2008 at 12:22pm UTC
for (int i=1; i<=12; i++)cout<<i*i<<" " ;
Topic archived. No new replies allowed.