当前位置:网站首页>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
边栏推荐
- Data mining - a discussion on sample imbalance in classification problems
- 【指针】删除字符串s中的所有空格
- Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class
- Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
- Based on authorized access, cross host, and permission allocation under sqlserver
- Web vulnerability - File Inclusion Vulnerability of file operation
- Low income from doing we media? 90% of people make mistakes in these three points
- 2022华中杯数学建模思路
- 《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
- 关于交换a和b的值的四种方法
猜你喜欢

Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?

外网打点(信息收集)

《统计学》第八版贾俊平第三章课后习题及答案总结

“人生若只如初见”——RISC-V

Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class

Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class

《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案

《统计学》第八版贾俊平第五章概率与概率分布

Detailed explanation of network foundation routing

Build domain environment (win)
随机推荐
Fire! One day transferred to go engineer, not fire handstand sing Conquest (in serial)
【指针】删除字符串s中的所有空格
On the idea of vulnerability discovery
关于超星脚本出现乱码问题
List and data frame of R language experiment III
Lintcode logo queries the two nearest saplings
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
Attack and defense world misc practice area (simplerar, base64stego, no matter how high your Kung Fu is, you are afraid of kitchen knives)
《英特尔 oneAPI—打开异构新纪元》
XSS (cross site scripting attack) for security interview
使用 flask_whooshalchemyplus jieba实现flask的全局搜索
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
函数:计算字符串中大写字母的个数
Tencent map circle
Record once, modify password logic vulnerability actual combat
Data mining - a discussion on sample imbalance in classification problems
How to earn the first pot of gold in CSDN (we are all creators)
四元数---基本概念(转载)
Detailed explanation of network foundation routing
1.支付系统