-
Catfish
nested loops
Here's what I need to do! I need to write a nested loop code segment that produces the following output:
1
1 2
1 2 3
1 2 3 4
I know that this is elementary to most of you. I know how to make the program increment numbers:
int i = 1;
while(i < 5)
{
cout << i <<endl;
i++;
}
but how do get it to go back to 1 and inrement to 2 then on the next line 1 2 3, etc. I know I need to nest the loops but I am fairly new to loops, I am a beginner, and not sure how to make it produce the output listed above. I am not asking anyone to do this program for me only asking for some hints and direction. THANK YOU!!!!
-
Tiger Shark
Re: nested loops
Originally posted by f15e
Here's what I need to do! I need to write a nested loop code segment that produces the following output:
1
1 2
1 2 3
1 2 3 4
I know that this is elementary to most of you. I know how to make the program increment numbers:
int i = 1;
while(i < 5)
{
cout << i <<endl;
i++;
}
but how do get it to go back to 1 and inrement to 2 then on the next line 1 2 3, etc. I know I need to nest the loops but I am fairly new to loops, I am a beginner, and not sure how to make it produce the output listed above. I am not asking anyone to do this program for me only asking for some hints and direction. THANK YOU!!!!
int j = 1;
while (j<5)
{
int i = 1;
while(i < j)
{
cout << i << " ";
i++;
}
cout << i << endl;
}
I want an OS, not a hobby...
Theres nothing more pathetic then someone who wears non-matching socks on purpose.
-
Catfish
DeadKen
THANKS DeadKen!!!
I appreciate your help! I needed to add a j++ to the end of the code and it worked. THANKS AGAIN!!!
-
How's about Java codes for producing the following:
1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
Thanks !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|