I have a problem, I try to sort tabs and display them. User inputs number of how many tabs he wants to sort, but the last tab is not displayed.
I am beginner. How can I find where I made an error?
I tried tracking n integer, it resets to 0 after sorting the last tab, probably sorting algorithm messes it up, but I don't know how.
#include<iostream>
using namespace std;
void bsort(int tab[]) {
for(int i=0; i<sizeof(tab)-1; i++) {
for(int j=0; j<sizeof(tab)-1; j++) {
if(tab[j] < tab[j+1]) swap(tab[j+1], tab[j]);
}
}
}
int main() {
int t, n;
cin >> t;
for(int i=0; i<t; i++) {
cin >> n;
int tab[n];
for(int j=0; j<n; j++) {
cin >> tab[j];
}
bsort(tab);
cout << n << endl;
for(int k=0; k<n; k++) {
cout << tab[k] << " ";
}
}
return 0;
}