Powered By Blogger

Tuesday 3 May 2011

cs201 assignment solution 2


#include<iostream.h>
#include<conio.h>
main()
{
 int ary1[3][3],ary2[3][3],ary[18],index,temp,max;
 cout<<"Please enter the Elements of First Matrix: ";
 for(int n=0;n<3;n++)
 {
         for(int m=0;m<3;m++)
         {
                 cin>>ary1[n][m];
         }
 }
cout<<"Please enter the Elements of second Matrix: ";
 for(int n=0;n<3;n++)
 {
         for(int m=0;m<3;m++)
         {
                 cin>>ary2[n][m];
         }
 }

 //Copying first array into single dimenional array
 index=0;
 for(int n=0;n<3;n++)
 {
         for(int m=0;m<3;m++)
         {
                 ary[index]=ary1[n][m];
                 index++;
         }
 }
//Copying second array into single dimenional array
 index=9;
 for(int n=0;n<3;n++)
 {
         for(int m=0;m<3;m++)
         {
                 ary[index]=ary2[n][m];
                 index++;
         }
 }

 // Here sorting the third array in which ary1 and ary2 are copped....
 // This sorting method is bubble sorting method in decending order.

 for(int n=0;n<18;n++)
 {
         for(int m=n;m<18;m++)
         {
                 if(ary[n]<ary[m])
                 {            
                          temp=ary[n];
                          ary[n]=ary[m];
                          ary[m]=temp;
                 }
         }

 }
 //Show arranged array in decending order
cout<<"Sorted Values from Both the Matrices are: "<<endl;
for(int n=0;n<18;n++)
{
        cout<<ary[n]<<" ";
}
getch();
}

No comments:

Post a Comment