数组
- #include <stdio.h>
- int main(int argc, const char * argv[]) {
-
- int a[10],sum,temp;
- float ave ;
- printf("请输入十个数据:\n");
- for (int i=0; i<10; i++) {
- scanf("%d",&a[i]);
- }
- printf("\n");
- for (int i=0; i<9; i++) {
- for (int j=0; j<9-i; j++) {
- if (a[i]>a[i+1]) {
- temp= a[i];
- a[i]= a[i+1];
- a[i+1]=temp;
- }
- }
- }
- for (int i=0; i<=9; i++) {
- sum+=a[i];
- printf("%d\t",a[i]);
- }
- ave = (float)sum/10;
- printf("\n");
- printf("max=%d,min=%d,sum=%d,ave=%.2f\n",a[9],a[0],sum,ave);
- return 0;
- }
复制代码 |