当前位置:网站首页>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
边栏推荐
猜你喜欢

Wei Shen of Peking University revealed the current situation: his class is not very good, and there are only 5 or 6 middle-term students left after leaving class

WEB漏洞-文件操作之文件包含漏洞

Proceedingjoinpoint API use

Network technology related topics

链队实现(C语言)

Xray and burp linkage mining

关于交换a和b的值的四种方法

攻防世界MISC练习区(gif 掀桌子 ext3 )

JDBC transactions, batch processing, and connection pooling (super detailed)

Intranet information collection of Intranet penetration (3)
随机推荐
How to turn wechat applet into uniapp
Solutions to common problems in database development such as MySQL
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
MySQL中什么是索引?常用的索引有哪些种类?索引在什么情况下会失效?
Intranet information collection of Intranet penetration (3)
图书管理系统
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
链队实现(C语言)
网络基础之路由详解
[err] 1055 - expression 1 of order by clause is not in group by clause MySQL
Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
Applet Web Capture -fiddler
【指针】八进制转换为十进制
内网渗透之内网信息收集(四)
记一次api接口SQL注入实战
How to earn the first pot of gold in CSDN (we are all creators)
Windows platform mongodb database installation
Binary search tree concept