I am trying to get this number pattern
Input: 7
Output:
1 1 1 1 1 1 1
1 2 2 2 2 2 1
1 2 3 3 3 2 1
1 2 3 4 3 2 1
1 2 3 3 3 3 1
1 2 2 2 2 2 1
1 1 1 1 1 1 1
But I can't figure out how to make it like that, any suggestion how to make that pattern??
My code so far :
int n, temp1, temp2,i,j;
cin >> n;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
temp1 = j;
temp2 = n-j+1;
if (temp1 < temp2) cout << temp1;
else cout << temp2;
}
cout << endl;
}
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire