当前位置:网站首页>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
边栏推荐
- 《统计学》第八版贾俊平第四章总结及课后习题答案
- Intel oneapi - opening a new era of heterogeneity
- Hcip -- MPLS experiment
- Internet Management (Information Collection)
- 5分钟掌握机器学习鸢尾花逻辑回归分类
- The most popular colloquial system explains the base of numbers
- JVM memory model concept
- Xray and burp linkage mining
- 【指针】使用插入排序法将n个数从小到大进行排列
- WEB漏洞-文件操作之文件包含漏洞
猜你喜欢
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
记一次edu,SQL注入实战
图书管理系统
线程的实现方式总结
How to earn the first pot of gold in CSDN (we are all creators)
“人生若只如初见”——RISC-V
浅谈漏洞发现思路
Attack and defense world misc practice area (GIF lift table ext3)
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
Web vulnerability - File Inclusion Vulnerability of file operation
随机推荐
XSS之冷门事件
XSS unexpected event
{1,2,3,2,5}查重问题
Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
内网渗透之内网信息收集(四)
. Net6: develop modern 3D industrial software based on WPF (2)
Low income from doing we media? 90% of people make mistakes in these three points
内网渗透之内网信息收集(五)
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
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
Hackmyvm target series (1) -webmaster
c语言学习总结(上)(更新中)
循环队列(C语言)
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
MySQL learning notes (stage 1)
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
DVWA (5th week)
Load balancing ribbon of microservices
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
【指针】求字符串的长度