Hi I'm newbie in programming and having troublesome with some of my homework...anybody can help me?? Here is the question.
Write an iterative function called OperateFloatArray that take in a float array
floatarray, an integer parameter numrec (which determines the number of float values in the array) and a character parameter op (which stores any one of the 4 characters '+', '-', '/' and '*'). If floatarray = {1.0,2.0,3.0} and numrec = 3;
OperateFloatArray (floatarray, numrec, '+') returns 6.0 (1.0 + 2.0 + 3.0),
OperateFloatArray (floatarray, numrec, '-') returns -4.0 (1.0 - 2.0 - 3.0).
OperateFloatArray (floatarray, numrec, '/') returns 0.16667 ((1.0 / 2.0) / 3.0).
OperateFloatArray (floatarray, numrec, '*') returns 6.0 (1.0 * 2.0 * 3.0).
I got the model function cannot make it works coz i'm useless in programming. Here is it....
float OperateFloatArray (float floatarray[], int numrec, char op)
{
int x;
float sum=0, product=1;
float diff=floatarray[0], quotient=floatarray[0];
if (op == '+')
{ for (x=0; x < numrec; x++)
sum = sum + floatarray
return sum;
}
if (op == '-')
{ for (x=1; x < numrec; x++)
diff = diff - floatarray
return diff;
}
Any helps is really appreciated....Thanks in advance.....