大一新生,对编程很感兴趣,才写了个程序有一个错,不知道在哪,求助!!!
程序代码:
#include <stdio.h> /*是为了根据用户选择来处理用户输入的数据*/ void main() { int a[10]; int i,j,t,n; char ch; float av; printf("input 10 numbers :\n"); for (i=0;i<10;i++) /*请用户输入要求处理的10个数据*/ scanf("%d",&a[i]); printf("\n"); printf("A: From small to big\nB: From big to small\nC: The maximum and minimum\nD: Average\n");/*提示用户各选项功能*/ printf("\n"); printf("Please from A, B, C, D of choice.\n"); scanf("%c",ch); switch { case'A': { for(j=0;j<9;j++) { n=0; for(i=0;i<9-j;i++) if (a[i]>a[i+1]) { t=a[i];a[i]=a[i+1]; a[i+1]=t; n++;} if(n==0) break; } printf("From small to big numbers :\n"); for(i=0;i<10;i++) { printf("%d",a[i]); printf("\n"); } } break; case'B': { for(j=0;j<9;j++) { n=0; for(i=0;i<9-j;i++) if (a[i]<a[i+1]) { t=a[i];a[i]=a[i+1]; a[i+1]=t; n++;} if(n==0) break; } printf("From big to small numbers :\n"); for(i=0;i<10;i++) { printf("%d",a[i]); printf("\n"); } } break; case'C': { for(j=0;j<9;j++) { n=0; for(i=0;i<9-j;i++) if (a[i]<a[i+1]) { t=a[i];a[i]=a[i+1]; a[i+1]=t; n++;} if(n==0) break; } printf("The maximum numbers :%d\n",a[0]); printf("The minimum numbers :%d\n",a[9]); } break; case'D': { n=0; for(j=0;j<9;j++) n=n+a[i]; av=n/10; printf("The average: %5.2f",av); }break; default:printf("enter data error!"); } }