当前位置:网站首页>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
边栏推荐
- 关于交换a和b的值的四种方法
- DVWA (5th week)
- 《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
- c语言学习总结(上)(更新中)
- XSS (cross site scripting attack) for security interview
- 记一次edu,SQL注入实战
- 循环队列(C语言)
- Library management system
- Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
- . Net6: develop modern 3D industrial software based on WPF (2)
猜你喜欢
《英特尔 oneAPI—打开异构新纪元》
Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
xray與burp聯動 挖掘
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
How to earn the first pot of gold in CSDN (we are all creators)
Attack and defense world misc practice area (simplerar, base64stego, no matter how high your Kung Fu is, you are afraid of kitchen knives)
Hcip -- MPLS experiment
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
Applet Web Capture -fiddler
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
随机推荐
captcha-killer验证码识别插件
《统计学》第八版贾俊平第二章课后习题及答案总结
Applet Web Capture -fiddler
Hcip -- MPLS experiment
MSF generate payload Encyclopedia
Windows platform mongodb database installation
Feature extraction and detection 14 plane object recognition
Network technology related topics
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
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
XSS之冷门事件
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
Chain team implementation (C language)
指针--剔除字符串中的所有数字
内网渗透之内网信息收集(二)
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
Sentinel overall workflow
This article explains in detail how mockmvc is used in practical work
【指针】求字符串的长度
Attack and defense world misc practice area (simplerar, base64stego, no matter how high your Kung Fu is, you are afraid of kitchen knives)