60 525
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #32220 in C++ for amin

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);
}
}
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions