本帖最后由 jackz007 于 2022-9-29 22:08 编辑 #include<stdio.h>
int main(void)
{
int a[10] , n , j , num , flag = 0 ;
for(n = 0 ; n <= 9 ; n ++) {
printf("Please enter ten number which you want to calculate:(n-n)") ;
scanf("%d", &a[n]) ;
if(a[n] < a[n-1]) { // 这个排序不彻底
a[n] = j ; // j = ?这一句不是在砸场子吗
a[n - 1] = a[n] ;
a[n - 1] = j ;
}
}
for(flag = 1 ; flag <= 8 ; flag ++) num = num + a[flag] ; // num 没有初始化为 0
printf("The result is:%d\n" , num / 8) ;
return 0 ;
}
请参考我修改的代码:#include<stdio.h>
int main(void)
{
int a[10] , i , j , n , num , t ;
for(n = 10 , i = 0 ; i < n ; i ++) {
printf("Please enter ten number which you want to calculate : (n-n) ") ;
scanf("%d", & a[i]) ;
for(j = i ; j && a[j] < a[j - 1] ; j --) {
t = a[j - 1] ;
a[j - 1] = a[j] ;
a[j] = t ;
}
}
for(num = 0 , i = 1 ; i < n - 1 ; i ++) num += a[i] ;
printf("The result is : %.2f\n" , 1.0 * num / 8.0) ;
}
编译、运行实况:D:\[00.Exerciese.2022]\C>g++ -o x x.c
D:\[00.Exerciese.2022]\C>x
Please enter ten number which you want to calculate : (n-n) 7
Please enter ten number which you want to calculate : (n-n) 4
Please enter ten number which you want to calculate : (n-n) 8
Please enter ten number which you want to calculate : (n-n) 2
Please enter ten number which you want to calculate : (n-n) 5
Please enter ten number which you want to calculate : (n-n) 9
Please enter ten number which you want to calculate : (n-n) 10
Please enter ten number which you want to calculate : (n-n) 5
Please enter ten number which you want to calculate : (n-n) 7
Please enter ten number which you want to calculate : (n-n) 3
The result is : 6.00
D:\[00.Exerciese.2022]\C>
|