VĂ ROG AJUTOR!!!!! OFER 100 DE PUNCTE
Răspunsuri la întrebare
1
#include<iostream>
using namespace std;
int main(){
int n, v[100];
cin>>n;
//SelectionSort
for(int i=1;i<=n;i++) cin>>v[i];
for(int i=1;i<=n-1;i++)
for(int j=i+1;j<=n;j++)
if(v[i]>v[j]) {
int aux=v[i];
v[i]=v[j];
v[j]=aux;
}
//BubbleSort
int sortat;
do {
sortat=1;
for(int i=1;i<=n-1;i++)
if(v[i]>v[i+1]) {
int aux=v[i];
v[i]=v[i+1];
v[i+1]=aux;
sortat=0;
}
} while(!sortat);
for(int i=1;i<=n;i++) cout<<v[i]<<' ';
}
2
#include<iostream>
using namspace std;
int prim(int x){
for(int d=2;d<=x/2;d++) if (x%d) return 0;
return 1;
}
int main(){
int v[6][6], x[40], k=1;
for(int i=1; i<=5; i++)
for(int j=1;j<=5;j++){
cin>>v[i][j];
if(prim(v[i][j])==1) x[k++]=v[i][j];
}
//SelectionSort - ascendent
for(int i=1;i<=k-1;i++)
for(int j=i+1;j<=k;j++)
if(x[i]>x[j]) {
int aux=x[i];
x[i]=x[j];
x[j]=aux;
}
//BubbleSort - ascendent
int sortat;
do {
sortat=1;
for(int i=1;i<=k-1;i++)
if(x[i]>x[i+1]) {
int aux=x[i];
x[i]=x[i+1];
x[i+1]=aux;
sortat=0;
}
} while(!sortat);
for(int i=1;i<=k;i++) cout<<x[i]<<' ';
cout<<endl;
//SelectionSort - descendent
for(int i=1;i<=k-1;i++)
for(int j=i+1;j<=k;j++)
if(x[i]<x[j]) {
int aux=x[i];
x[i]=x[j];
x[j]=aux;
}
//BubbleSort - descendent
int sortat;
do {
sortat=1;
for(int i=1;i<=k-1;i++)
if(x[i]<x[i+1]) {
int aux=x[i];
x[i]=x[i+1];
x[i+1]=aux;
sortat=0;
}
} while(!sortat);
for(int i=1;i<=k;i++) cout<<x[i]<<' ';
}