当前位置:网站首页>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;
}边栏推荐
- [NLP]—sparse neural network最新工作简述
- JVM原理简介
- Pdf editing tool movavi pdfchef 2022 direct download
- Know that Chuangyu cloud monitoring - scanv Max update: Ecology OA unauthorized server request forgery and other two vulnerabilities can be detected
- What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets
- 金仓数据库KingbaseES 插件kdb_exists_expand
- MySQL field userid comma separated save by userid query
- The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
- 金仓数据库KingbaseES 插件kdb_database_link
- 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
猜你喜欢

Preliminary cognition of C language pointer

Daily question - ugly number

JS realizes lazy loading of pictures

2022 t elevator repair simulation examination question bank and t elevator repair simulation examination question bank

After reviewing MySQL for a month, I was stunned when the interviewer of Alibaba asked me

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 test the concurrency of kingbasees, there are sub threads that are not closed in time after the main process is killed successfully

Golang -- realize file transfer
随机推荐
X-ray normal based contour rendering
Feature_selection
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
Database management tool, querious direct download
Web - Information Collection
[set theory] set identities (idempotent law | exchange law | combination law | distribution rate | De Morgan law | absorption rate | zero law | identity | exclusion law | contradiction law | complemen
金仓数据库KingbaseES 插件kdb_exists_expand
2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination
Kingbasees plug-in KDB of Jincang database_ exists_ expand
Php+mysql registration landing page development complete code
Smart contract security audit company selection analysis and audit report resources download - domestic article
220214c language learning diary
Daily question - ugly number
Writing skills of multi plate rotation strategy -- strategy writing learning materials
AWS VPC
2022 tea master (intermediate) examination questions and tea master (intermediate) examination skills
Kubernetes源码分析(一)
Why should programmers learn microservice architecture if they want to enter a large factory?
[Thesis Writing] how to write the overall design of JSP tourism network