array in outer function

Hello!


Is function OrderArray using m2[5] from main or sth else?

All the other is ok functioning!!!

Many thansk!

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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  #include<iostream>
#include<stdlib.h>
using namespace std;

void Change(int& first, int& second){
int medium=first;
first=second;
second=medium;
}

void OrderArray(int array2[], int index_max){
for (int trans=0;trans<index_max-1;trans++){
       for (int i=0;i<index_max;i++){
             if (array2[i]>array2[i+1])
                   {Change(array2[i],array2[i+1]);}
       }
}

}


void PrintArray(int array3[], int index_max){
   for (int i=0;i<index_max;i++)
   cout<<array3[i]<<" ";
cout<<endl;
}



void Array1dAdd(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;
               a+=z1[i][j];

              cout<<z1[i][j]<<" ";
    }
m1[i]=a;
cout<<"     "<<a;
cout<<endl;
a=0;
}

cout<<endl;
for(int d=0;d<5;d++){
cout<<m1[d]<<" ";
}


}

void Generate(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 m2[5];
int index_max_main=5;
int m[5][3];

cout<<"This is Generate: "<<endl<<endl;
Generate(m);
cout<<endl;
cout<<"This is Array1dAdd: "<<endl<<endl;
Array1dAdd(m);


OrderArray(m2,index_max_main);
cout<<endl<<endl<<endl;
cout<<"This is ordered m1:: ";
PrintArray(m2, index_max_main);

return 0;
}
 




(p.s. I s indentation any better? At least I am trying!)
void OrderArray(int array2[], int index_max)

receives an int[] and an int returns nothing

1
2
main(){....
OrderArray(m2,index_max_main);


Passes an int[] named m2 and an int named index_max_main to OrderArrray.
Hello!žHow can I get the array m1[5] to get MEMORISED in main and translated to other functions?


P.s. Problem is just cause it is an array. I would know hwa tto do with int.
Many thanks!
Topic archived. No new replies allowed.