当前位置:网站首页>Pointers: maximum, minimum, and average
Pointers: maximum, minimum, and average
2022-07-06 14:35:00 【|Light|】
requirement
Programming , Enter a one-dimensional integer array , Output the maximum value 、 Minimum and average .( Use a pointer to achieve )
Code
#include<stdio.h>
/* * This function is used to input a one-dimensional integer array , The input data is stored in the formal parameter a Array * Input data in 0 As an end sign ,0 It is not stored in the array nor included in the total number of input data * The return value is the number of input data */
int input(int a[])
{
int n=0;
int b = 0;
do
{
scanf("%d",&b);
if(b == 0)
break;
else
{
a[n] = b;
n++;
}
}
while(b != 0);
return n;
}
/* * This function is used to calculate the formal parameter array a Maximum of 、 minimum value 、 Average * Maximum 、 minimum value 、 The average value passes through the formal parameter pointer variable pmax、pmin、pavg To pass on * n Is a formal parameter array a Number of data in */
void fun(int a[],int *pmax,int *pmin,int *pavg,int n)
{
int i,j,k=0;
*pmax = a[0];
*pmin = a[0];
for(i=1;i<n;i++)
{
if(*pmin > a[i])
{
*pmin = a[i];
}
if(*pmax < a[i])
{
*pmax = a[i];
}
k = k + a[i];
*pavg = (k + a[0])/n;
}
}
main function
int main()
{
int a[200],n,max,min,avg;
n=input(a);
fun(a,&max,&min,&avg,n);
printf(" The maximum value is %d, The minimum value is %d, The average value is %d\n",max,min,avg);
return 0;
}
test
Test input
1 3 5 7 0
Output
The maximum value is 7, The minimum value is 1, The average value is 4
边栏推荐
- Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
- sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
- Sentinel overall workflow
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
- An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
- 浅谈漏洞发现思路
- Xray and burp linkage mining
- How to test whether an object is a proxy- How to test if an object is a Proxy?
- 《统计学》第八版贾俊平第四章总结及课后习题答案
- 【指针】查找最大的字符串
猜你喜欢
JDBC看这篇就够了
Low income from doing we media? 90% of people make mistakes in these three points
How does SQLite count the data that meets another condition under the data that has been classified once
网络基础之路由详解
Detailed explanation of network foundation
Record once, modify password logic vulnerability actual combat
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
四元数---基本概念(转载)
Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
Matplotlib绘图快速入门
随机推荐
【指针】数组逆序重新存放后并输出
JVM memory model concept
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
Chain team implementation (C language)
Record once, modify password logic vulnerability actual combat
ES全文索引
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
Data mining - a discussion on sample imbalance in classification problems
Interview Essentials: what is the mysterious framework asking?
WEB漏洞-文件操作之文件包含漏洞
数据库多表链接的查询方式
Windows platform mongodb database installation
JDBC transactions, batch processing, and connection pooling (super detailed)
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
内网渗透之内网信息收集(三)
Ucos-iii learning records (11) - task management
Which is more advantageous in short-term or long-term spot gold investment?
内网渗透之内网信息收集(一)