Narim, очень торопился, поэтому чтобы не закорачиваться везде использовал целый тип. Я думаю перевести где нужно в вещественный труда не составит?
| Код | #include <stdio.h> #include <stdlib.h> #include <time.h>
//----------------------------------------------// void SetValues(unsigned *arr, unsigned count, unsigned min, unsigned max) { srand(time(NULL)); while (count--) { arr[count] = rand()%(max-min) + min; } } //----------------------------------------------// void Print(unsigned *arr, unsigned count) { while (count--) { printf("%4d", arr[count]); } printf("\n"); } //----------------------------------------------// void CalculationYield(unsigned *crop, unsigned *area, unsigned *yield, unsigned count) { while (count--) { yield[count] = area[count] / crop[count]; } } //----------------------------------------------// unsigned AllYield(unsigned *crop, unsigned *area, unsigned count) { unsigned sumCrop = 0; unsigned sumArea = 0; while (count--) { sumCrop += crop[count]; sumArea += area[count]; } return sumArea / sumCrop; } //----------------------------------------------//
#define SIZE 10
int main() { unsigned crop[SIZE], area[SIZE], yield[SIZE]; SetValues(crop, SIZE, 1, 15); SetValues(area, SIZE, 30, 40);
printf("crop\n"); Print(crop, SIZE);
printf("area\n"); Print(area, SIZE);
CalculationYield(crop, area, yield, SIZE);
printf("yield\n"); Print(yield, SIZE);
printf("middle = %d\n", AllYield(crop, area, SIZE)); return 0; }
|
|