The problem wants me to create a main function that allows users to enter a list of numbers, then create a function that finds the largest entry in magnitude then switch the largest entry that I found to the second last entry and finally print out the entire array
I'm having some difficulties in getting this program to print out the final array.
Code:
#include <stdio.h>
int selection_sort(int n, int a[]);
int main ()
{
int number, a[10]={0};
printf("Please enter 10 numbers: \n");
int i;
for (i=0; i<10; i++)
{
scanf("%d", &a[i]);
}
selection_sort(10, a[i]);
for (i=0; i<10;i++)
{
printf("\n and the numbers in the list are: \n", a[]);
}
return 0;
}
int selection_sort (int n, int a[])
{
int cur, nxt, largest, i;
for (cur = 0, nxt = 1; nxt < n; cur++, nxt++)
{
if (a[cur]>a[nxt])
{
largest = a[cur];
}
else if (a[nxt]>a[cur])
{
largest = a[nxt];
}
else
{
cur++;
nxt++;
}
}
printf("\nthe largest number in the list is:", largest);
a[n-1]=largest;
return a[n];
}
Please trace through the program and find the error, thanks in advance!