Borderandry
14-06-2017, 15:12
Bella raga,
ho creato un programma (per scuola, studio in Russia) in cui ordino i numeri di un array in ordine crescente, con certe quantità funziona, con certe no, una mano?
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Here all the numbers you will put shall be ordered from the smallest to the biggest\nHow many numbers do you want to insert?"<<endl;
cin>>n;
int *mass = new int[n];
cout<<"Please insert "<<n<<" numbers"<<endl;
for (int x=0;x<n;x++){
cin>>mass[x];
}
int transf = 0;
for (int y=0;y<n;y++){
for (int z=0;z<n-y;z++){
if (mass[z]>mass[z+1]){
transf=mass[z];
mass[z]=mass[z+1];
mass[z+1]=transf;
}
}
}
cout<<"Here, have your numbers sorted in crescent order:"<<endl;
for(int a=0;a<n;a++){
cout << mass[a] <<endl;
}
return 0;
}
ho creato un programma (per scuola, studio in Russia) in cui ordino i numeri di un array in ordine crescente, con certe quantità funziona, con certe no, una mano?
#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Here all the numbers you will put shall be ordered from the smallest to the biggest\nHow many numbers do you want to insert?"<<endl;
cin>>n;
int *mass = new int[n];
cout<<"Please insert "<<n<<" numbers"<<endl;
for (int x=0;x<n;x++){
cin>>mass[x];
}
int transf = 0;
for (int y=0;y<n;y++){
for (int z=0;z<n-y;z++){
if (mass[z]>mass[z+1]){
transf=mass[z];
mass[z]=mass[z+1];
mass[z+1]=transf;
}
}
}
cout<<"Here, have your numbers sorted in crescent order:"<<endl;
for(int a=0;a<n;a++){
cout << mass[a] <<endl;
}
return 0;
}