C语言:求大神们帮忙看看哪里不对,该怎么改。

2025-05-17 15:07:07
推荐回答(2个)
回答1:

"找出最大的是第几个数"的算法没有看懂。

直接比较a[i]和a[A]不就行了

for (i = 1; i < 10; ++i)
    if (a[i] > a[A]) A = i;

回答2:

#include 
#include
#include

/*YOu can write the sort algorithm here, may be any method, like buble, or quick*/
void sort(int[], int num);
/*here we used with like below, will be easy th change the size of array*/
#define LENGTH 10
int main()//要求输入10个整数,按顺序排列10个数,找出其中最大数,并确认是第几个数。
{
int a[LENGTH];
/*memset initial the array a all to 0*/
memset(a, 0, sizeof(int) * LENGTH);
/*initial the max number to int min limits and index to 1*/
int max_element = INT_MIN; 
int index = 1;
for (int i = 0; i< LENGTH; ++i)//输入10个数
{
scanf_s("%d", &a[i]);
if (a[i] > max_element){
max_element = a[i];
index = i + 1;
}
}
/* here can sort the array.
*/
sort(a, LENGTH);
printf("The MAx number is %d, the place is %d\n", max_element, index);
return 0;
}