I am working on a program to rewrite an assortment of integers in increasing order yet they are in decreasing order. I am pretty sure the problem is in my indexMax or sortArray functions but I cant find it. Can anyone help?
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"
#define size 7
void sortArray (int num[]);
int indexMax(int num[], int low, int high);
void swap (int num[], int loc1, int loc2);
void getArray (int num[]);
void displayArray (int num[]);
int main()
{
int num[size];
getArray(num);
sortArray(num);
displayArray(num);
}
void getArray (int num[])
{
int i;
for (i=0; i<size; i++)
{
printf("Enter integer: \n");
num[i]=GetInteger();
}
}
void displayArray (int num[])
{
int i;
printf("\nThe sorted list is: \n");
for (i=0; i<size; i++)
{
printf("%d\n", num[i]);
}
}
void sortArray (int num[])
{
int i, maxInd;
for (i=0; i<size; i++)
{
maxInd=indexMax (num, i, size-1);
swap (num, i, maxInd);
}
}
int indexMax (int num[], int low, int high)
{
int i, maxInd;
maxInd=low;
for (i=low;i<=high;i++)
{
if (num[i]<num[maxInd])
{
maxInd=i;
}
}
return (maxInd);
}
void swap (int num[], int loc1, int loc2)
{
int temp;
temp=num[loc1];
num[loc1]=num[loc2];
num[loc2]=temp;
}