You are on page 1of 2

question #01

#include <iostream> #include <iomanip> using namespace std; int main() {int det; int array[2][2]; for(int i=0;i<2;i++) for(int j=0;j<2;j++) cin>>array[i][j]; cout<<"\t"; cout<<"Matrix is "<<endl<<endl<<array[0][0]<<setw(10)<<array[0] [1]<<endl<<endl<<endl<<array[1][0]<<setw(10)<<array[1][1]; cout<<endl; det=(array[0][0]*array[1][1]-array[0][1]*array[1][0]); cout<<endl<<endl<<"Determinent is = "<<det<<endl; return 0; }

question #02
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; void selectionSort( int [], int ); int main() { const int SIZE = 10, MAXRANGE = 1000; int sortThisArray[ SIZE ] = { 0 }; srand( time( 0 ) ); for ( int i = 0; i < SIZE; ++i ) sortThisArray[ i ] = 1 + rand() % MAXRANGE; cout << "\nUnsorted array is:\n"; for ( int j = 0; j < SIZE; ++j ) cout << ' ' << sortThisArray[ j ] << ' ';

selectionSort( sortThisArray, SIZE ); cout << "\n\nSorted array is:\n"; for ( int k = 0; k < SIZE; ++k ) cout << ' ' << sortThisArray[ k ] << ' '; cout << '\n' << endl; return 0; } void selectionSort( int array[], int size ) { int temp; if ( size >= 1 ) { for ( int loop = 0; loop < size; ++loop ) if ( array[ loop ] < array[ 0 ] ) {temp = array[ loop ]; array[ loop ] = array[ 0 ]; array[ 0 ] = temp; } selectionSort( &array[ 1 ], size - 1 ); } }

You might also like