how to sort an array ascending, help
Hy , this is my code, i am a beginner, i just want to make a program that will request an int array[10] and will rearange it asecenetly,
the problem seems easy to solve but is not.
#include <iostream>
using namespace std;
void v(int q[],int fc[]);
void main() {
int i[10];
int h[10];
for (int a= 0;a<10;a++){
cout<<"\n\t h["<<a<<"] = ";
cin>> h[a];
}
v(h,i);
for(a=0;a<10;a++){
cout << "\n\t i["<<a<<"] ="<<i[a];
}
}
void v(int ui[],int ui2[]) {
int r;
int s(0);
for(int i=0;i<10;i++) {
if(r<ui[i]) {
r=ui[i];
}
}
for(int y=9;y>-1;y--) {
for (i=0;i<10;i++) {
if((ui2[y]<ui[i]) && (ui2[y]<r)) { // *
ui2[y] = ui[i]; s++;
}
r= ui2[y];cout<<"\n\t r="<<r; // **
}
}
return;
}
* : the problem here : cannot see why the if statement functions in that manner, just compile it and see
** i just wrote taht to see at each loop ending if the r is well implemented , it is not, it should have been the last biggest number smaller than the preious biggest one
|