0

Program to arrange numbers in ascending order

using array or any method ( input 10 numbers)

25th Nov 2016, 4:18 PM
BridaSwan
3 Respuestas
+ 1
#include <iostream> using namespace std; int v[100],n,i,j,aux; int main(){ cin>>n; for(i=1;i<=n;i++) cin>>v[i]; for(i=1;i<n;i++) for(j=i+1;j<=n;j++) if(v[i]>v[j]){ aux=v[i]; v[i]=v[j]; v[j]=aux; } for(i=1;i<=n;i++) cout<<v[i]<<" "; return 0; } There you go :)
25th Nov 2016, 8:00 PM
Valentin Marin
Valentin Marin - avatar
+ 1
easy solution :) http://www.sololearn.com/app/cplusplus/playground/cg6Bl8bBFb3h/ #include <iostream> #include <algorithm> using namespace std; int main() { int array[10] = { 0, }; for (int i = 0; i < 10; ++i) { cin >> array[i]; } sort(array, array + 10); for (int i = 0; i < 10; ++i) { cout << array[i] << " "; } cout << "\n"; return 0; }
26th Nov 2016, 2:41 AM
kiwiyou
kiwiyou - avatar
0
thanks
26th Nov 2016, 6:00 AM
BridaSwan