i wrote up a program using functions to calculate a sum and product. I looked it over and it looks right to me, but im not getting the desired values...
not really sure where i went wrong, thanks for the help.Code:#include <stdio.h> #define MAX_ELEMS 100 void SumAndProduct (double[], int, double, double); int main() { double arr[MAX_ELEMS]; int count = 0; double val, sum, product; printf("Enter array values (or 0.0 to stop): "); do { scanf("%lf", &val); if(val!=0.0) { arr[count]=val; count++; } } while( val != 0.0 && count < MAX_ELEMS); SumAndProduct(arr, count , sum, product); printf("The sum is %f and the product is %f. \n", sum, product); return 0; } void SumAndProduct( double a[], int len, double sum, double prod) { int i; prod = 1.0; sum = 0.0; for(i=0; i< len;i++) { sum = sum + a[i]; prod = prod * a[i]; } }



LinkBack URL
About LinkBacks



