| vaflyboy03 (20) | |
|
# include <iostream> # include <ctime> # include <cmath> # include <iomanip> # include <fstream> # include <cstdlib> using namespace std; void readmatrix(int [5][4]); void printmatrix(int [5][4]); void sortlow(int[5][4]); void sorthigh(int [5][4]); int main() { int infile; ifstream input ("ARRAY.DAT"); //ofstream output ("ARRAYSORT1.OUT"); int array1[5][4]; readmatrix (array1); printmatrix (array1); cout<<endl<<endl; sorthigh(array1); printmatrix(array1); cout<<endl<<endl; sortlow(array1); printmatrix(array1); system("pause"); } void readmatrix(int x[5][4]) { int rows,columns,input; for (rows=0;rows<5;rows++) for (columns=0;columns<4;columns++) input>>x[rows][columns]; } void printmatrix(int y[5][4]) { int rows,columns; for (rows=0;rows<5;rows++) { for (columns=0;columns<4;columns++) cout<<y[rows][columns]<<" "<<endl; } } void sorthigh(int sort[5][4]) { int high,m,i,a,n,row; int end=5; int temp1[4],temp2[4]; for (m=end-1;m>=0;m--) { high = sort[m][0]; for (i=m;i>=0;i--) { if (high >= sort[i][0]) { high = sort[i][0]; row =i; } for (a=0;a<4;a++) { temp1[a] = sort[m][a]; temp2[a] = sort[row][a]; sort[m][a] = temp2[a]; sort[row][a] = temp1[a]; } } } void sortlow(int sort[5][4]) { int low,m,i,a,n,row; int end=5; int temp1[4],temp2[4]; for (m=end-1;m>=0;m--) { low = sort[m][0]; for (i=m;i>=0;i--) { if (low <= sort[i][0]) { low = sort[i][0]; row =i; } for (a=0;a<4;a++) { temp1[a] = sort[m][a]; temp2[a] = sort[row][a]; sort[m][a] = temp2[a]; sort[row][a] = temp1[a]; } } } } line 85 | |
|
|
|
| Grey Wolf (2909) | |
|
What is the error you are getting! How To Ask Questions The Smart Way http://www.cplusplus.com/forum/articles/1295/ How to put code into your postings http://www.cplusplus.com/forum/articles/1624/ | |
|
|
|