I am working on a program that takes an integer array and puts it into separate functions that display the sum, the product, the average, and which number in the array is largest and smallest. I got it to work somewhat, but I'm having difficulties. The functions for sum, product, and average give me the correct results, but the functions to compare the numbers are not so lucky. I was able to get one of them to work, but not the other. When comparing for the smallest number, it display a number that does not exist in the array. In a different method, which I don't remember what it was, it displayed -3, when -4 is the smallest. How do I correct this?
here is the source for finding the smallest number:
and here is the source for the program, if it helps:
here is the source for finding the smallest number:
Code:
int comparelow(int n[], int size)
{
int count2, part;
int low;
part = 0;
for (count2 = 0; count2 >= size -1; count2++)
{
while (part != size -1)
{
if (n[count2] < n[part])
{
low = n[count2];
}
part++;
}
}
return low;
}
and here is the source for the program, if it helps:
Code:
#include <stdio.h>
#include "simple.h"
#define Size 10
int main()
{
int number[Size] = {12, 2, 6, -4, 2, 9, 7, 1, 8, -3};
int items = Size;
printf("Sum is %d\n", sum(number, items));
printf("Average is %d\n", mean(number, items));
printf("Product is %d\n", product(number, items));
printf("Smallest is %d\n", comparelow(number, items));
printf("Largest is %d\n", compare(number, items));
return 0;
}