1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Location
ミンダナオ、フィリピン
Posts
4
Rep Power
0

#### Help? [2dArray]

May I know how to make a right to left square matrix?
I only made a left to right so far orz (I'm still learning so don't bite my head off please!)

This is my left to right code:

Code:
```#include<stdio.h>
#define COL 5
#define ROW 5

int main(){

int array[COL][ROW];
int i,k;

for(k=0;k<COL;k++){
for(i=0;i<ROW;i++){

if(k==i){
array[k][i]=0;
}
if(k<i){
array[k][i]=1;
}
if(k>i){
array[k][i]=-1;
}
}
}

for(k=0;k<COL;k++){
for(i=0;i<ROW;i++)
printf("%5d",array[k][i]);
printf("\n");

}

printf("\n");

system("pause");
return 0;
}```
May I know what operation was to reverse it to right to left?
It should be like this...
1 1 1 1 0
1 1 1 0 -1
1 1 0 -1 -1
1 0 -1 -1 -1
0 -1 -1 -1 -1
2. yes, you're actually allowed to use arithmetic to compute indexes.
Code:
```#include<stdio.h>
#define COL 5
#define ROW 5

int main(){

int array[COL][ROW];
int i,k,j;

for(k=0;k<COL;k++){
for(i=0;i<ROW;i++){
j = ROW-(1+i);
if(k==i)
array[k][j]=0;
if(k<i)
array[k][j]=1;
if(k>i)
array[k][j]=-1;
}
}

for(k=0;k<COL;k++){
for(i=0;i<ROW;i++)
printf("%5d",array[k][i]);
printf("\n");

}

printf("\n");

system("pause");
return 0;
}```
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Location
ミンダナオ、フィリピン
Posts
4
Rep Power
0
AHH! THANK YOU SO MUCH! マジどうもありがとございます！ww