why are these 2 functions generating the same array=
Hello!
Please, how to achieve that each function generates ANOTHER 2dd array?
Many thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include<iostream>
#include<stdlib.h>
using namespace std;
void Array1d(int z1[][3]){
srand (time(NULL));
int m1[5];
int a=0;
for (int i=0;i<5;i++){
for (int j=0;j<3;j++){
z1[i][j]=rand()% 10;
cout<<z1[i][j]<<" ";
a+=z1[i][j];
}
cout<<endl;;
m1[i]=a;
a=0;
}
cout<<endl;
for(int d=0;d<5;d++){
cout<<m1[d]<<" ";
}
}
void Add(int d1[][3]){
srand (time(NULL));
for (int i=0;i<5;i++){
for (int j=0;j<3;j++){
d1[i][j]=rand()% 10;
cout<<d1[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
int m[5][3];
Add(m);
cout<<endl;
Array1d(m);
return 0;
}
|
do not call srand()
twice. Put it on top of the main()
function
Works!!!
MANY THANKS!!!
Topic archived. No new replies allowed.