اكتب برنامج لادخال مصفوفة ثنائية البعد حجمها 2*2 ويعمل الأتي
- برمجة
- برمجة سي بلس بلس
- 2021-04-14
- salsabeelalhams99111801528
الأجوبة
#include<iostream>
using namespace std;
int main(){
int a[4][4],x;
cout<<"enter the elements\n";
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
cin>>a[i][j];
int max=a[0][0];
int min=a[0][0];
int count=0;
do{
cout<<"press 1 to print All
elements:\n ";
cout<<"press 2 to print elements
reverse:\n";
cout<<"press 3 to printprimarg
diagonal elements:\n";
cout<<"press 4 to secondary
diadonal:\n";
cout<<"press 5 to find maximum
element:\n";
cout<<"press 6 to find minum
element:\n";
cout<<"press 7 toshort elements:\n";
cout<<"press 8 to print even
number:\n";
cout<<"press 9 to print odd
number:\n";
cout<<"press 10 to search the number
in array:\n";
cout<<"press 0 to exit:\n";
cin>>x;
switch(x){
case 1:for(int i=0;i<4;i++){
cout<<endl;
for(int j=0;j<4;j++)
cout<<a[i][j]<<" ";}break;
case 2:for(int i=3;i>=0;i--){
cout<<endl;
for(int j=3;j>=0;j--)
cout<<a[i][j]<<" ";}break;
case 3:for(int i=0;i<4;i++){
cout<<endl;
for(int j=0;j<4;j++)
if(i==j)
cout<<a[i][j];
else cout<<" ";}break;
case 4:for(int i=0;i<4;i++){
cout<<endl;
for(int j=0;j<4;j++)
if(i+j==3)
cout<<a[i][j];
else cout<<" ";}break;
case 5:
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
if(a[i][j]>max)max=a[i][j];
cout<<"the max is="<<max;break;
case 6:
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
if(a[i][j]<min)min=a[i][j];
cout<<"the min is="<<min;break;
case 7:int n,m,tem;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
for(int n=i;n<4;n++)
for(int m=j;m<4;m++)
if(a[n][m]<a[i][j]){
tem=a[n][m];
a[n][m]=a[i][j];
a[i][j]=tem;}
for(int i=0;i<4;i++){
cout<<"\n";
for(int j=0;j<4;j++)
cout<<a[i][j]<<"\t";}break;
case 8:for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
if(a[i][j]%2==0)
cout<<a[i][j]<<" ";
else cout<<" ";
cout<<endl; break;
case 9:for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
if(a[i][j]%2!=0)
cout<<a[i][j]<<" ";
else cout<<" ";break;
case 10: int x;
cout<<"enter the number for search\n";
cin>>x;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
if(a[i][j]==x)
count++;
if(count>0)
cout<<"fonut"<<count<<"times\n";break;
default:
cout<< "pad choice try agin"<<endl;
break;
}}while(x!=0);
return 0;}
القوائم الدراسية التي ينتمي لها السؤال