Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

two dimensional array A[N,M] with the random numbers from 10 to 90.

#include <iostream>
#include <ctime> // For time()
#include <cstdlib>  // For srand() and rand() 
#include <iomanip>
using namespace std;
 int table[5][10];
void sortarray (int[], int);
void showarray (int[], int);

int main()
{
	const int row=5;
	const int column=10;
	int table[row][column];
	int rnum;
	int t[row];
	
	srand(time(0));  // Initialize random number generator. 
	rnum = (rand() % 100) + 1;	
	


	for(int r=0; r<row; r++)//row	
	{ for(int c=0; c<column; c++)
	table [r][c] = (rand()%100) + 1;
	}
	
	for(int r=0; r<row; r++)//row	
	{ for(int c=0; c<column; c++) //column
	 
	{ 
		cout << setw(5) << table[r][c] << ' '; //display table
		 
	}
		cout << endl;
	}   


sortarray (t, row);

	cout << "your new sorted table is:  ";
	 showarray ( t, row);


	
	
	system("pause");		
	return 0;

}



void sortarrray(int t[], int elems)
{
	int temp;
	bool swap;

	do
	{
		swap=false;
		for (int count=0; count < (elems-1); count++)
		{
			if (t[count] > t[count +1])
			{ 
				 temp = t[count];
				t[count]=t[count +1];
				t[count +1]= temp;
				swap=true;
			}
		}
	}while (swap);
}





void showarray (int t[], int elems)
{
	for (ount] << " ";
	cout << endl;int count=0; count < elems; count++)
		cout << t[c
}
Source by www.daniweb.com #
 
PREVIOUS NEXT
Tagged: #dimensional #array #random #numbers
ADD COMMENT
Topic
Name
6+6 =