当前位置:网站首页>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;
}边栏推荐
- Golang -- realize file transfer
- [文献阅读] Sparsity in Deep Learning: Pruning and growth for efficient inference and training in NN
- GFS distributed file system (it's nice to meet it alone)
- BMZCTF simple_ pop
- P35-P41 fourth_ context
- How do you use lodash linking function- How do you chain functions using lodash?
- Which code editor is easy to use? Code editing software recommendation
- [graduation season · aggressive technology Er] Confessions of workers
- [literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
- [set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
猜你喜欢

一名外包仔的2022年中总结

When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error

Feature_selection

Employee attendance management system based on SSM

vulnhub HA: Natraj

Asp access teaching management system design finished product

X-ray normal based contour rendering

消息队列(MQ)介绍
![[Thesis Writing] how to write the overall design of JSP tourism network](/img/02/841e8870c2ef871c182b9bb8252a83.jpg)
[Thesis Writing] how to write the overall design of JSP tourism network

After reviewing MySQL for a month, I was stunned when the interviewer of Alibaba asked me
随机推荐
How to retrieve the password for opening word files
Busycal latest Chinese version
Smart contract security audit company selection analysis and audit report resources download - domestic article
RSRS指标择时及大小盘轮动
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
vulnhub HA: Natraj
[set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
[untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
sd卡数据损坏怎么回事,sd卡数据损坏怎么恢复
mysql字段userid逗号分开保存按userid查询
跨境电商多商户系统怎么选
Design and implementation of JSP logistics center storage information management system
金仓数据库KingbaseES 插件kdb_date_function
BMZCTF simple_ pop
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
Use the benchmarksql tool to perform a data prompt on kingbases. The jdbc driver cannot be found
Sklearn data preprocessing
Xrandr modifier la résolution et le taux de rafraîchissement
How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?