数字统计

本文介绍了一个用于查找整型数组中的最大值与最小值及其出现次数的C语言函数。通过一次遍历完成排序并统计,提高了查找效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include "OJ.h"
#include<stdio.h>
#include<stdlib.h>


/*
功能:对输入的整型数组,输出数组元素中的最大值、最大值的个数、最小值和最小值的个数
    
输入:int * pInputInteger:整型数组指针
int * InputNum:数组元素个数
    
输出:int * pMaxValue:数组中最大值
  int * pMaxNum:数组中最大值的个数
int * pMinValue:数组中最小值
     int * pMinNum:数组中最小值的个数
     
返回:void
*/
void OutputMaxAndMin(int * pInputInteger, int InputNum, int * pMaxValue, int * pMaxNum, int * pMinValue, int * pMinNum)
{
/*在这里实现功能*/
if (InputNum <= 0 || pInputInteger == NULL)
{
*pMaxNum = 0;
*pMinNum = 0;
*pMaxValue = 0;
*pMinValue = 0;
return ;
}
int i, j;
* pMaxNum = 0;
* pMinNum = 0;
for(i = 0;i<InputNum-1;i++)
for (j = 1;j<InputNum;j++)
{
if (pInputInteger[i] > pInputInteger[j])
{
int temp = pInputInteger[i];
pInputInteger[i] = pInputInteger[j];
pInputInteger[j] = temp;
}
}
* pMaxValue = pInputInteger[InputNum-1];
* pMinValue = pInputInteger[0];
for(i = 0;i<InputNum;i++)
{
if(* pMinValue == pInputInteger[i])
(* pMinNum)++;
else if(* pMaxValue == pInputInteger[i])
(* pMaxNum)++;
}
return;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值