当前位置:网站首页>Pointeurs: maximum, minimum et moyenne
Pointeurs: maximum, minimum et moyenne
2022-07-06 14:34:00 【Lumière】
Exigences
Écrire le programme,Saisissez un tableau d'entiers unidimensionnels,Valeur maximale de sortie、Minimum et moyenne.(Avec un pointeur)
Code
#include<stdio.h>
/* * Cette fonction est utilisée pour saisir un tableau d'entiers unidimensionnels,Les données saisies sont stockées dans des paramètres formelsaDans le tableau * Données saisies pour0Comme signe de fin,0Ne pas enregistrer dans le tableau et ne pas compter dans le total des données d'entrée * La valeur de retour est le nombre de données d'entrée */
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;
}
/* * Cette fonction est utilisée pour calculer le tableau des paramètres formelsaMax in、Minimum、Moyenne * Max.、Minimum、La moyenne passe par les variables du pointeur de paramètrepmax、pmin、pavgPour passer * nEst un tableau de paramètres formelsaNombre de données dans */
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;
}
}
mainFonctions
int main()
{
int a[200],n,max,min,avg;
n=input(a);
fun(a,&max,&min,&avg,n);
printf("Max.%d,Min.%d,La moyenne est%d\n",max,min,avg);
return 0;
}
Tests
Test Input
1 3 5 7 0
Produits
Max.7,Min.1,La moyenne est4
边栏推荐
- Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?
- How to earn the first pot of gold in CSDN (we are all creators)
- Ucos-iii learning records (11) - task management
- 使用 flask_whooshalchemyplus jieba实现flask的全局搜索
- Binary search tree concept
- Sentinel overall workflow
- “人生若只如初见”——RISC-V
- 网络基础详解
- JDBC看这篇就够了
- [paper reproduction] cyclegan (based on pytorch framework) {unfinished}
猜你喜欢
Network layer - simple ARP disconnection
Harmonyos JS demo application development
xray與burp聯動 挖掘
外网打点(信息收集)
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
链队实现(C语言)
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
Constants, variables, and operators of SystemVerilog usage
Database monitoring SQL execution
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
随机推荐
WEB漏洞-文件操作之文件包含漏洞
How to turn wechat applet into uniapp
浅谈漏洞发现思路
【指针】删除字符串s中的所有空格
《统计学》第八版贾俊平第三章课后习题及答案总结
Circular queue (C language)
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
Intel oneapi - opening a new era of heterogeneity
MSF generate payload Encyclopedia
Hackmyvm target series (5) -warez
Harmonyos JS demo application development
Xray and Burp linked Mining
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
线程的实现方式总结
How to test whether an object is a proxy- How to test if an object is a Proxy?
Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
内网渗透之内网信息收集(一)
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class
. Net6: develop modern 3D industrial software based on WPF (2)