finding largest element of array
I am working on the function largest_element that seeks to find largest element of array. Now I am not sure if I set it up correctly to find the largest element. And also, I am not sure if call it correctly, (or have understandable arguments).
[CODE]
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define NUMELEM 30
#define MAXELEM 200
void ascend_sort(int a[],int n);
void descend_sort(int a[], int n);
void random_array(int a[], int n);
int largest_element (int a[], int f, int l);
main()
{
int array[NUMELEM];
int last=0;
/* create array */
/* find largest element */
/* sort in ascending order using selection sorting */
/* sort in descending order using selection sorting */
/* print new arrays */
random_array(array,NUMELEM);
/* need to call function largest_element to use later */
last=largest_element(array,array[0],array[NUMELEM-1]);
printf("%d",last);
}
/* FUNCTION: largest_element : my resource text says to */
/* make i and j point to the first element of array (but it */
/* does not assume a[0] is the first element for some */
/* reason; f and l are representing first and last elements */
/* of array passed */
int largest_element(int a[], int f, int l)
{
int i=f;
int j=f;
do {
i++;
if (a[i] > a[j]) {
j=i;
}
} while (i != l);
return j;
}
void ascend_sort(int a[],int n)
{
int largest;
int temp;
}
void descend_sort(int a[], int n)
{
}
void random_array(int a[], int n)
{
int i;
for (i=0; i < NUMELEM ; i++)
{
a[i] = rand()%MAXELEM+1;
printf("%3d ",a[i]);
if ((i+1)%10==0)
printf("\n");
}
}