-
For Loops
Help!!!!!
How can nested for loops be used to print numbers in this format?
1
23
345
4567
ANY help will be greatly appreciated!!
-
Re: For Loops
This is a good logic problem...figure it out!
You'll find that you'll get more assistance if
you at least show what you have so far...
"Christy" <sprynter0@yahoo.com> wrote:
>
>Help!!!!!
>
>How can nested for loops be used to print numbers in this format?
>
>1
>23
>345
>4567
>
>ANY help will be greatly appreciated!!
>
>
>
-
Re: For Loops
//
//
#include <iostream>
#include <conio.h>
int n;
Yeah, I agree...what I've got so far might be helpful..thanks for the tip...
int main()
{
for ( int a = 1 ; a <= 1; a++ ){
cout << a <<endl;
for ( int a = 1; a <= 2; a++ ) {
cout<< a << endl; }
for ( int a = 1; a <= 3; a++ )
cout << a << endl;
}
}getche();
return 0;
}
this is the output I'm trying to obtain
1
23"Mark C" <mdcashion@hotmail.com> wrote:
>
>This is a good logic problem...figure it out!
>
>You'll find that you'll get more assistance if
>you at least show what you have so far...
>
>"Christy" <sprynter0@yahoo.com> wrote:
>>
>>Help!!!!!
>>
>>How can nested for loops be used to print numbers in this format?
>>
>>1
>>23
>>345
>>4567
>>
>>ANY help will be greatly appreciated!!
>>
>>
>>
>
-
Re: For Loops
Here is something you might want to try.
int j = 2, total = 5, count = 0;
for (int i = 1; i < total; i++)
{
cout << i;
count = 0;
for (int ii = 2; ii < j; ii++)
cout << (j + count++);
j++;
cout << endl;
}
Basically you need a loop for the column and another loop for rows. You
just need to keep track of how you increment the values.
Later
Ken
"christy" <sprynter0@yahoo.com> wrote:
>
>//
>//
>
>#include <iostream>
>#include <conio.h>
>
>int n;
>
>Yeah, I agree...what I've got so far might be helpful..thanks for the tip...
>
>int main()
>{
> for ( int a = 1 ; a <= 1; a++ ){
> cout << a <<endl;
> for ( int a = 1; a <= 2; a++ ) {
> cout<< a << endl; }
> for ( int a = 1; a <= 3; a++ )
> cout << a << endl;
> }
> }getche();
> return 0;
>
>}
>this is the output I'm trying to obtain
>1
>23"Mark C" <mdcashion@hotmail.com> wrote:
>>
>>This is a good logic problem...figure it out!
>>
>>You'll find that you'll get more assistance if
>>you at least show what you have so far...
>>
>>"Christy" <sprynter0@yahoo.com> wrote:
>>>
>>>Help!!!!!
>>>
>>>How can nested for loops be used to print numbers in this format?
>>>
>>>1
>>>23
>>>345
>>>4567
>>>
>>>ANY help will be greatly appreciated!!
>>>
>>>
>>>
>>
>
-
Re: For Loops
Try this out,
#include <iostream>
using std::cout;
using std::endl;
int main()
{
for (int row = 1 ; row <= 4; ++row)
{
for (int column = 0; column < row; ++column)
{
cout << (row + column);
}
cout << endl;
}
return 0;
}
"Christy" <sprynter0@yahoo.com> wrote:
>
>Help!!!!!
>
>How can nested for loops be used to print numbers in this format?
>
>1
>23
>345
>4567
>
>ANY help will be greatly appreciated!!
>
>
>
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks