当前位置:网站首页>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
边栏推荐
- 安全面试之XSS(跨站脚本攻击)
- . Net6: develop modern 3D industrial software based on WPF (2)
- Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
- 《统计学》第八版贾俊平第三章课后习题及答案总结
- Feature extraction and detection 14 plane object recognition
- captcha-killer验证码识别插件
- Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class
- Markdown font color editing teaching
- C language file operation
- Binary search tree concept
猜你喜欢

JVM memory model concept

servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。

xray與burp聯動 挖掘

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

On the idea of vulnerability discovery

《統計學》第八版賈俊平第七章知識點總結及課後習題答案

Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques

Intel oneapi - opening a new era of heterogeneity

. Net6: develop modern 3D industrial software based on WPF (2)

内网渗透之内网信息收集(四)
随机推荐
内网渗透之内网信息收集(三)
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
【指针】求解最后留下的人
AQS details
flask实现强制登陆
JVM memory model concept
Markdown font color editing teaching
Chain team implementation (C language)
Bing Dwen Dwen official NFT blind box will be sold for about 626 yuan each; JD home programmer was sentenced for deleting the library and running away; Laravel 9 officially released | Sifu weekly
Interview Essentials: what is the mysterious framework asking?
外网打点(信息收集)
New version of postman flows [introductory teaching chapter 01 send request]
内网渗透之内网信息收集(四)
Constants, variables, and operators of SystemVerilog usage
Detailed explanation of network foundation
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
使用 flask_whooshalchemyplus jieba实现flask的全局搜索
Feature extraction and detection 14 plane object recognition
指针:最大值、最小值和平均值
Library management system