Double dimension arrays store variable in a rows*columns size matrix. We input them using nested for loops which basically means one for loop inside another. Here i make use of logical AND operator(&&) which means that if and only if both the statements are true , the code inside the if is executed. The first square bracket specifies the rows, the second specifies the columns.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
using namespace std;
int main()
{
int i, j;
char A[5][9];
for(i=0; i<5; i++)
{
for(j=0; j<9; j++)
{
if((j>=i)&&(j<9-i))
{
A[i][j]='*';
}
else
{
A[i][j]=' ';
}
}
}
for(i=0; i<5; i++)
{
for(j=0;j<9;j++)
{
cout<<A[i][j];
}
cout<<"\n";
}
return 0;
}
OUTPUT:
