Question #32220

I wrote a program to descrite a domain (1*1) to i*i cells. (i cells per edge). I want to write two arrays x[i][i] and y[i][i] for (x,y) of centers of cells. The origin is on the south west of the domain, but the program assign 0 to all of x and y array. what is the problem??????????????
for (int m=0; m<i; m++){
for(int n=0; n<i; n++){
x[m][n]=(2*m+1)/(2*i);
y[m][n]=(2*n+1)/(2*i);
}
}

Expert's answer

#include <iostream>

using namespace std;

int main() {

int i = 10;

double x[10][10], y[10][10];

//the problem is that you have division int on int.

// you have transfer int into double in one of terms

for (int m=0; m < i; m++){

for(int n=0; n < i; n++){

x[m][n]=double(2*m+1)/(2*i);

y[m][n]=double(2*n+1)/(2*i);

}

}

};

using namespace std;

int main() {

int i = 10;

double x[10][10], y[10][10];

//the problem is that you have division int on int.

// you have transfer int into double in one of terms

for (int m=0; m < i; m++){

for(int n=0; n < i; n++){

x[m][n]=double(2*m+1)/(2*i);

y[m][n]=double(2*n+1)/(2*i);

}

}

};

## Comments

## Leave a comment