+ 2
How can I make the binary array to be zeroes in the middle ?
example 1 1 1 1 1 1 1 0 1 1 1 000 1 1 1 0 1 1 1 1 1 1 1 // my code CODE #include <iostream> using namespace std; void generaMB1(int n, int m[][25]){ int f,c; for(f=0;f<n;f++){ for(c=0;c<n;c++){ if((f+c)==3 || (f+c)==4 || (f+c)==5 && f!=1 && c!=1 && f!=0 && f!=4 ){ m[f][c]=0; }else{ m[f][c]=1; } } } } void listaMatriz(int n, int m[][25]){ cout << endl << "LISTADO DE LA MATRIZ"<<endl; for(int f=0;f<n;f++){ for(int c=0;c<n;c++){ cout <<" "<<m[f][c]; } cout << endl; } } int main(int argc, char *argv[]) { int m[25][25]; int n=5; generaMB1(n, m); listaMatriz(n, m); return 0; }
2 Antworten
+ 1
you could always hard code it.....
int x = [
[1 1 1 1 1]
[1 1 0 1 1]
[1 0 0 0 1]
[1 1 0 1 1]
[1 1 1 1 1]];
//missing commas... not syntactically correct :/
+ 1
maybe:
int mid = n/2;
if ((f == mid && c!=0 && c!=n-1) || (c == mid && f!=0 && f!=n-1))
{m[f][c] = 0}
else
{m[f][c]=1}