Informatică, întrebare adresată de Danu19id1, 8 ani în urmă

Se considera tabloul bidimensional A[1..n,1..m] cu elemente intregi.Sa se compuna un program care va rearanja coloanele matricei A astfel incat elementele de pe ultima sa linie sa fie in ordinea descrescatoare prin metoda selectiei,fara a folosi o matrice noua.Matricea modificata sa fie afisata pe ecran.
Program in C++,va rog frumos

Răspunsuri la întrebare

Răspuns de cristiit
0

#include <iostream>

#include <vector>

using namespace std;

int r=3;

int c=3;

int ordonare(){

int tabel[r][c]{{1,1,2},

                 {2,3,4},

                 {2,3,5}};

   int x=0;

   int y=0;

//functia de ordonare

if(tabel[1][0]>tabel[0][0]){

int x1=tabel[0][0];

tabel[0][0]=tabel[1][0];

tabel[1][0]=x1;

}

if(tabel[2][0]>tabel[0][0]){

int x1=tabel[0][0];

tabel[0][0]=tabel[2][0];

tabel[2][0]=x1;

}

if(tabel[2][0]>tabel[1][0]){

int x1=tabel[0][0];

tabel[1][0]=tabel[2][0];

tabel[2][0]=x1;

}

}

int f1(){

int tabel[r][c]{{6,1,2},

               {2,9,3},

               {2,3,7}};

/*int x2=tabel[1][0];

int x3=tabel[2][0];

int x4=tabel[0][1];

int x5=tabel[1][1];

int x6=tabel[2][1];

int x7=tabel[0][2];

int x8=tabel[1][2];

int x9=tabel[2][2];*/

int j=0;

for(int x=0; x<c; x++){

if(tabel[2][x]>tabel[1][x]){

int x1=tabel[1][x];

tabel[1][x]=tabel[2][x];

tabel[2][x]=x1;

}

if(tabel[1][x]>tabel[0][x]){

int x1=tabel[0][x];

tabel[0][x]=tabel[1][x];

tabel[1][x]=x1;

}

if(tabel[2][x]>tabel[0][x]){

int x1=tabel[1][x];

tabel[0][x]=tabel[2][x];

tabel[2][x]=x1;

}

if(tabel[1][x]>tabel[1][x]){

int x1=tabel[1][x];

tabel[1][x]=tabel[2][x];

tabel[2][x]=x1;

}

if(tabel[2][x]>tabel[1][x]){

int x1=tabel[1][x];

tabel[1][x]=tabel[2][x];

tabel[2][x]=x1;

}

}

for(int i=0; i<r; i++){

   cout<<tabel[i][j];

}

cout<<endl;

j++;

for(int i=0; i<r; i++){

   cout<<tabel[i][j];

}

j++;

cout<<endl;

for(int i=0; i<r; i++){

   cout<<tabel[i][j];

}

if(j==2){

   j=0;

}

cout<<endl;

}

int main()

{

f1();

}

Nu respecta exact cerinta dar il mai modifici tu .

Alte întrebări interesante