当前位置:网站首页>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 Shandong Province safety officer C certificate examination content and Shandong Province safety officer C certificate examination questions and analysis
- Human resource management system based on JSP
- Smart contract security audit company selection analysis and audit report resources download - domestic article
- [NLP]—sparse neural network最新工作简述
- vulnhub HA: Natraj
- [fairseq] error: typeerror:_ broadcast_ coalesced(): incompatible function arguments
- IPhone x forgot the boot password
- Preliminary cognition of C language pointer
- [fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries
- x Problem B
猜你喜欢

arthas watch 抓取入参的某个字段/属性

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

Two points -leetcode-540 A single element in an ordered array

Five elements of user experience

使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭

GFS distributed file system (it's nice to meet it alone)

The latest activation free version of Omni toolbox

Youdao cloud notes

2022 Shandong Province safety officer C certificate examination content and Shandong Province safety officer C certificate examination questions and analysis

Asp access teaching management system design finished product
随机推荐
Reptile exercise 03
[set theory] binary relationship (special relationship type | empty relationship | identity relationship | global relationship | divisive relationship | size relationship)
GFS分布式文件系统(光是遇见已经很美好了)
Busycal latest Chinese version
Why should programmers learn microservice architecture if they want to enter a large factory?
SSM based campus part-time platform for College Students
When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
Competitive product analysis and writing
Feature_selection
vulnhub HA: Natraj
[no title] 2022 chlorination process examination content and free chlorination process examination questions
因子选股-打分模型
解决bp中文乱码
Ffmpeg mix
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
消息队列(MQ)介绍
PostgreSQL database high availability Patroni source code learning - etcd class
Basic MySQL operations
How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
sd卡数据损坏怎么回事,sd卡数据损坏怎么恢复