Write the program:
a) Write a program that takes call arguments (as real numbers) and states whether they form a sorted sequence (non-ascending, e.g. 5, 5, 4, 3, 1, 1 or non-descending, e.g. 1, 1, 2, 3, 3, 4),
b) if the answer from point a) is negative, output this string to the console after sorting.
When I put in console numbers for example: 8 5 0 9
it sorts good --> 0 5 8 9
but when I put more than 9
number for example 8 5 0 9 14 13
it sorts wrong --> 0 14 13 5 8 9
.
What is wrong with my code?
int main(int argc, char **argv) {
for (int i = 0; i < argc - 1; i++) {
int pos = i;
for (int j = i + 1; j < argc; j++) {
if (argv[j][0] < argv[pos][0]) {
pos = j;
}
}
char *tmp = argv[i];
argv[i] = argv[pos];
argv[pos] = tmp;
}
for (int i=0; i<argc-1 ; i++) {
cout << argv[i] << " ";
}
return 0;
}
How to check if they sorted or not?