Page 1 of 1

Reputation:

# Printing Array

Posted 29 August 2010 - 06:29 PM

Hiya. How do you print an array like this:
123
234
345
456
....all the way to 10.

I tried using 2 for loops but keep printing a triangle.
```for (int i=1; i <=10; i++)
{
for ( int k=1; k<=3; k++)
cout << a[k];

}

```

Is This A Good Question/Topic? 0

## Replies To: Printing Array

### #2 KYA

• yay verily

Reputation: 3155
• Posts: 19,200
• Joined: 14-September 07

## Re: Printing Array

Posted 29 August 2010 - 06:53 PM

Not really clear, are the contents of the array numerical values where each subsequent entry has an increment of one for reach digit?

### #3 ericr2427

• D.I.C Regular

Reputation: 39
• Posts: 378
• Joined: 01-December 08

## Re: Printing Array

Posted 29 August 2010 - 06:55 PM

I believe you want to replace the second for loop with for ( int k=i; k<=3; k++). Also, in the first for loop, if you want it to print everything in the array, you want to initialize i to 0, because array indexes start at 0, not 1.

### #4 buffalobill

Reputation: 21
• Posts: 188
• Joined: 08-July 08

## Re: Printing Array

Posted 30 August 2010 - 11:58 PM

Your array has four rows and three columns
Your first loop controls the rows and your second loop controls the columns
So as mentioned above the end condition for the first loop should be <3
The end condition for second loop should be <4.
Now cout<<a[i][k]in the body of the second loop
This assumes that int a [][]={1,2,3,2,3,4,3,4,5,4,5,6;}is already initialized like this.Clearly this level of array initialization needs to be extended to get to ten. And as was mentioned above your loops should start with i and k being assigned 0