当前位置:网站首页>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;
}
边栏推荐
- [set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
- Matplotlib -- save graph
- 2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank
- 怎么用Kotlin去提高生产力:Kotlin Tips
- How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
- JVM原理简介
- Pdf editing tool movavi pdfchef 2022 direct download
- [fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries
- 使用BENCHMARKSQL工具对KingbaseES执行测试时报错funcs sh file not found
- xrandr修改分辨率与刷新率
猜你喜欢
X-ray normal based contour rendering
JS realizes lazy loading of pictures
2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank
Php+mysql registration landing page development complete code
[dynamic programming] subsequence problem
When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
C language series - Section 3 - functions
2022 P cylinder filling test content and P cylinder filling simulation test questions
Prefix and (continuously updated)
随机推荐
Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
[set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
Priv-app permission异常
Kingbasees plug-in KDB of Jincang database_ exists_ expand
Competitive product analysis and writing
Human resource management system based on JSP
[graduation season · aggressive technology Er] Confessions of workers
Library management system based on SSM
Feature_selection
2022-02-12 (338. Bit count)
Prefix and (continuously updated)
Php+mysql registration landing page development complete code
Reptile exercise 02
Auman Galaxy new year of the tiger appreciation meeting was held in Beijing - won the double certification of "intelligent safety" and "efficient performance" of China Automotive Research Institute
Youdao cloud notes
After job hopping at the end of the year, I interviewed more than 30 companies in two weeks and finally landed
[software testing-6] & Test Management
Design and implementation of JSP logistics center storage information management system
AWS VPC
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。