冒泡发,用vs说是栈坏了
#include <stdio.h>#include <stdlib.h>
int main()
{
int a = { 62, 53,34, 76, 13, 82, 93, 27, 52, 10 };
int tem = 0;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10-i; j++)
{
if (a>a)
{
tem = a;
a = a;
a = tem;
}
}
}
for (int i = 0; i < 10; i++)
printf("%d\n", a);
return 0;
}
求助啊
程序没错,你的是c++的语法,保存为.cpp文件,不要保存为.c #include <stdio.h>
#include <stdlib.h>
int main()
{
int a = { 62, 53,34, 76, 13, 82, 93, 27, 52, 10 };
int tem = 0, i, j; //偶在这里定义i, j
for (i = 0; i < 10; i++)//这里的int去掉了
{
for ( j = 0; j < 10-i; j++)//这里的int去掉了
{
if (a>a)
{
tem = a;
a = a;
a = tem;
}
}
}
for ( i = 0; i < 10; i++) //这里的int去掉了
printf("%d\n", a);
return 0;
}
改成这样,在偶的VC上能正确运行 把for中的10该成9就行了
页:
[1]