当前位置:网站首页>C Primer Plus Chapter 10, question 14 3 × 5 array
C Primer Plus Chapter 10, question 14 3 × 5 array
2022-07-03 04:29:00 【multydoffer】
Write a program , Prompt the user for input 3 Group number , Each group contains 5 individual double Number of types ( Assume that all users respond correctly , Non numeric data will not be entered ). The procedure shall accomplish the following tasks :
a. Store the data entered by the user in 3×5 In the ground array
b. Calculate each group (5 individual ) The average of the data
c. Calculate the average of all data
d. Find out 15 The maximum of the data
e. Print the results
Each task should be completed with a separate function ( Use variable length arrays as formal parameters ). To complete the task b, To write a function that calculates and returns the average value of a one-dimensional array , Call this function with a loop 3 Time . For functions that handle other tasks , You should take the entire array as an argument , To complete the task c and d The function of should return the result to the calling function .
Here is the code :
#include <stdio.h>
double average(int n, double arr[n]);
double max(int n, double arr[n]);
int main(void)
{
double arr[3][5];
int i;
printf("Enter an array of 3x5 (double):");
for(i = 0; i < 15; i++)
scanf("%lf", (double *)arr + i);
for(i = 0; i < 3; i++)
printf("Average for each row is: %.2lf\n", average(5, (double *)(arr + i)));
printf("Average for total is: %.2lf\n", average(15, (double *)arr));
printf("The max in your array is: %.2lf\n", max(15, (double *)arr));
return 0;
}
double average(int n, double arr[n])
{
double total = 0;
double * end = arr + n;
while(arr < end)
total += *arr++;
return total / n;
}
double max(int n, double arr[n])
{
double max = *arr;
double * end = arr + n;
while(arr < end)
{
if(max < *arr)
max = *arr;
arr++;
}
return max;
}边栏推荐
- 跨境电商多商户系统怎么选
- 2022 electrician (Advanced) examination papers and electrician (Advanced) examination skills
- IPhone x forgot the boot password
- C language series - Section 3 - functions
- Kubernetes源码分析(一)
- Priv app permission exception
- MC Layer Target
- P35-P41 fourth_ context
- [set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
- Busycal latest Chinese version
猜你喜欢

Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected

After job hopping at the end of the year, I interviewed more than 30 companies in two weeks and finally landed

Joint search set: the number of points in connected blocks (the number of points in a set)

JS realizes lazy loading of pictures

Fcpx template: sweet memory electronic photo album photo display animation beautiful memory

Which code editor is easy to use? Code editing software recommendation
![[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius](/img/01/c118725f74e39742df021b5dbcc33b.jpg)
[pat (basic level) practice] - [simple simulation] 1063 calculate the spectral radius

vulnhub HA: Natraj

Some information about the developer environment in Chengdu

使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错
随机推荐
怎么用Kotlin去提高生产力:Kotlin Tips
[fxcg] market analysis today
多板块轮动策略编写技巧----策略编写学习教材
Square root of X
2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
2022 P cylinder filling test content and P cylinder filling simulation test questions
FFMpeg example
vulnhub HA: Natraj
Daily question - ugly number
Prefix and (continuously updated)
[Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
[NLP]—sparse neural network最新工作简述
JS realizes the animation effect of text and pictures in the visual area
xrandr修改分辨率与刷新率
[graduation season · aggressive technology Er] Confessions of workers
Priv-app permission异常
[set theory] binary relation (example of binary relation on a | binary relation on a)
Human resource management system based on JSP
Some information about the developer environment in Chengdu
MC Layer Target