exr10_11.c
来自「Software Development in C: A Practical A」· C语言 代码 · 共 66 行
C
66 行
//-----------------------------------------------
// Include Files
//-----------------------------------------------
#include <stdio.h>
#include <stdlib.h>
//End Include Files------------------------------
//-----------------------------------------------
// Constants
//-----------------------------------------------
const int ARRAY_LENGTH = 52;
const float MAXIMUM_WEEKLY_RAINFALL = 5.0;
//End Constants----------------------------------
int main()
{
int i;
float weeklyRainfall[ARRAY_LENGTH];
float totalYearlyRainfall;
float averageYearlyRainfall;
float temp;
// Fill the array with random numbers.
// For each array element...
for (i=0;i<ARRAY_LENGTH;i++)
{
/* Generate a random number that
represents the monthly rainfall in
inches. */
temp = rand();
/* While the number is greater than the
maximum number of inches of
rainfall possible ... */
while (temp > MAXIMUM_WEEKLY_RAINFALL)
{
// Divide the number by 10.
temp /= 10.0;
}
weeklyRainfall[i] = temp;
}
// For all weeks in the year...
/* Add the weekly rainfall to the
current total. */
// Calculate the average rainfall for the year.
// Print the weekly rainfall values.
// Print the total rainfall for the year.
// Print the average rainfall per week.
return (0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?