Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- cout<<"Write a program in C++ to execute the following\n";
- cout<<"1 : Insert items to the array (Whitout using cin)\n";
- int i,j,k=9,a[4][4];
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- a[i][j]=k;
- cout<<a[i][j]<<"\t";
- }
- cout<<endl<<endl;
- k-=3;
- }
- cout<<"--------------------------------------------------------\n";
- cout<<"2 : find odd numbers in the array , putting it to the 1D array and print it.\n";
- int b[7],t=0;
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- if(a[i][j]%2==1)
- {
- b[t]=a[i][j];
- t++;
- }
- }
- }
- for(i=0;i<t;i++)
- {
- cout<<b[i]<<"\t";
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"3 : find even numbers in the array , putting it to the 1D array and print it.\n";
- int p=0,c[7];
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- if(a[i][j]%2==0)
- {
- c[p]=a[i][j];
- p++;
- }
- }
- }
- for(i=0;i<p;i++)
- {
- cout<<c[i]<<"\t";
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"4 : Divided the array SE(4,4) to two array x(2,4) , y(2,4)\n";
- cout<<"X (2 , 4 )\n";
- for(i=0;i<=1;i++)
- {
- for(j=0;j<=3;j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl<<endl;
- }
- cout<<"Y (2 , 4 )\n";
- for(i=2;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl<<endl;
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"5 : swap first column with third column \n";
- int y;
- for(i=0;i<=3;i++)
- {
- y=a[i][0];
- a[i][0]=a[i][2];
- a[i][2]=y;
- }
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl<<endl;
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"6 : swap first row with third column \n";
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- y=a[0][j];
- a[0][j]=a[i][2];
- a[i][2]=y;
- }
- }
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl<<endl;
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"7 : swap second column with fourth row \n";
- int temp;
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- temp=a[i][1];
- a[i][1]=a[3][j];
- a[3][j]=temp;
- }
- }
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- cout<<a[i][j]<<"\t";
- }
- cout<<endl<<endl;
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"8 : find the minimum and maximum number in the array and print them \n";
- int max=0,mini=0;
- max=a[0][0];
- mini=a[i][j];
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- if(a[i][j]>max)
- max=a[i][j];
- else if(a[i][j]<mini)
- mini=a[i][j];
- }
- }
- cout<<"max : "<<max<<endl;
- cout<<"mini : "<<mini<<endl;
- cout<<"\n--------------------------------------------------------\n";
- cout<<"9 : inverse the array\n ";
- k=9;
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- a[i][j]=k;
- }
- k-=3;
- }
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- cout<<a[j][i]<<"\t";
- }
- cout<<endl<<endl;
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"10 : arrange number in the first row in ascending \n ";
- for(j=0;j<=3;j++)
- {
- if(a[0][j]>a[0][j+1])
- {
- temp=a[0][j];
- a[0][j]=a[0][j+1];
- a[0][j+1]=temp;
- }
- }
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- cout<<a[j][i]<<"\t";
- }
- cout<<endl<<endl;
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"11 : print the upper triangle \n";
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- if(i+j<3||i+j==3)
- {
- cout<<a[j][i];
- }
- cout<<"\t";
- }
- cout<<endl<<endl;
- }
- cout<<"\n--------------------------------------------------------\n";
- cout<<"12 : print sum of number in lower triangle \n";
- int sum=0;
- for(i=0;i<=3;i++)
- {
- for(j=0;j<=3;j++)
- {
- if(i+j>3||i+j==3)
- sum+=a[j][i];
- }
- }
- cout<<"Sum : "<<sum<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment