用C语言编写一个程序:从键盘输入n(0
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/22 01:24:34
用C语言编写一个程序:从键盘输入n(0
用C语言编写一个程序:从键盘输入n(0
用C语言编写一个程序:从键盘输入n(0
1:次数最多
2:在次数最多的基础上,数值最大
_______________________________________________以下为程序:
#include
// 设置最大值
#define MAX 100
typedef struct record
{
int number[MAX];
int counter[MAX];
}record;
int isExist(int array[], int index, record rd)
{
int i;
int flag = -1;
bool finish = true;
for (i = 0; i < index && finish; i++)
{
if (array[index] == rd.number[i])
{
flag = i;
finish = false;
}
}
return flag;
}
int findMaxNumber(record rd, int index)
{
int i = 0;
int flag = 0;
int maxNumber = rd.number[0];
int maxCounter = rd.counter[0];
while (i < index)
{
if (rd.counter[i] > maxCounter)
{
flag = i;
maxNumber = rd.number[i];
maxCounter = rd.counter[i];
}
else if (rd.counter[i] == maxCounter)
{
if (rd.number[i] > maxNumber)
{
flag = i;
maxNumber = rd.number[i];
maxCounter = rd.counter[i];
}
}
i++;
}
return flag;
}
int main()
{
int i;
int N;
int arr[MAX];
record rd;
int ct;
int find;
// 初始化结构体
for (i = 0; i < MAX; i++)
{
rd.counter[i] = 0;
rd.number[i] = 0;
}
// 输入整数的个数N
printf("Enter N (0