I want to sort members of an array a[]
with size s
. I have firstly used a function to get the elements, and then another function to sort them in ascending order. The problem is in the sort function or in main or in both of them, because the execution of the program ends just after entering the data. Is there anyone here that can help me?
#include <iostream>
using namespace std;
void getdata() {
int s;
cin >> s;
int a[s];
for (int i=0; i<s; i++) {
cin >> a[i];
}
}
void sort(int a[], int s) {
for (int i=0; i<s-1; i++) {
for (int j=i+1; i<s; i++) {
if (a[i] > a[j]) swap(a[i], a[j]);
}
}
}
int main () {
int a[100],s;
getdata();
sort(a, s);
return 0;
}