codigo python:
nx = 5
ny = 2
a=[[0]*nx]*ny
for x in range(0, ny):
for y in range(0, nx):
a[x][y]=x * nx + y
print(x * nx + y)
print("===========")
for x in range(0, ny):
for y in range(0, nx):
print(a[x][y])
nx = 5
ny = 2
a=[[0]*nx]*ny
for x in range(0, ny):
for y in range(0, nx):
a[x][y]=x * nx + y
print(x * nx + y)
print("===========")
for x in range(0, ny):
for y in range(0, nx):
print(a[x][y])
======================= codigo c++
#include <iostream>
using namespace std;
int main() {
const int nx=5;
const int ny=2;
double a [ny][nx];
for(int x=0; x<ny ; x++){
for(int y=0; y<nx ; y++)
{
a[x][y]=x*nx+y;
cout<<x*nx+y<<endl;
}
}
cout<<"============="<<endl;
for(int x=0; x<ny ; x++){
for(int y=0; y<nx ; y++)
{
cout<<a[x][y]<<endl;
}
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
const int nx=5;
const int ny=2;
double a [ny][nx];
for(int x=0; x<ny ; x++){
for(int y=0; y<nx ; y++)
{
a[x][y]=x*nx+y;
cout << x*nx+y << endl;
}
}
cout << "=============" << endl;
for(int x=0; x<ny ; x++){
for(int y=0; y<nx ; y++)
{
cout << a[x][y] << endl;
}
}
return 0;
}
================ por que¿Por qué no hacen lo mismo?