#include "stdafx.h"
#include
#define N 10 //数组长度固定
void main()
{
int i, j, num, a[N];//
int change, t;
printf("Enter Number: ");
scanf("%d", &num);
printf("Enter Data: \n");
for (i = 0; iscanf("%d", &a[i]);
for (i = num - 2, change = 1; i>0 && change; i--)//num-1
{
change = 0;
for (j = 0; j <= i; j++)
if (a[j]>a[j + 1])
{
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
change = 1;
}
}
printf("Sorted data:\n");
for (i = 0; iprintf("%d ", a[i]);
printf("\n");
}
a[num];
数组不允许元素为变量。
int i,j,num;
int change,t;
printf("Enter Number: ");
scanf("%d",&num);
int *a=new int[num];
前面几句改一下试试