I would like to write a program which finds the minimal number of 5 inputted numbers. I'm stuck at the point when I want to use function getMinNum, but there is an error saying: expected expression before ']' token I understand it has a connection with pointers, however I would like to do it without them if it is possible of course.
#include <stdio.h>
#include <stdlib.h>
float getMinNum(float a[], int x);
int main()
{
int n = 5;
int i;
float z[n];
for(i=0; i<n; i++){
scanf("%f", &z[i]);
}
printf("%6.2f", getMinNum(z[], n));
return 0;
}
float getMinNum(float a[], int x)
{
int i, min = a[0];
for(i=0; i<x; i++){
if(min > a[i+1]){
min = a[i+1];
}
}
return min;
}
getMinNum()withi = 1; you know thata[0]is the same value as what's inmin...well, ifminwas afloatand not anint, you would. You should check that thefscanf()calls all succeed before using the data. You're also using a VLA (variable length array). No harm done, but you should be aware that you're doing so.a[0]is a valid member. If you declarezwithfloat z[5], the compiler will enforce that assumption.