c++那位大哥帮我看看怎么运行时出错

来源:百度知道 编辑:UC知道 时间:2024/05/09 19:44:04
#include <iostream>
using namespace std;
int px(int a[],int n) //排序函数
{
int temp;
for (int i=0;i<n-1;i++)
{
for (int j=i+1;j<n-1;j++)
{
if (a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
for (int m=0;m<n;m++)
{cout <<"排序后的顺序为:"<<a[m]<<" "<<endl;}
return 0;
}

void main()
{
int n;
cin >>"请输入要排序的数的个数:">> n;
int *x;
x=new int[n];
for (int y=0;y<n;y++)
cin >>"请输入要排序的数">>x[y];
px(x,n);
delete []x;
}
这个程序我编译的时候没错,为什么运行的时候会出错?

你这里有好几处错误,我给你改好了,你自己对照一下吧...
#include <iostream>
using namespace std;
int px(int a[],int n) //排序函数
{
int temp;
for (int i=0;i<n-1;i++)
{
for (int j=i+1;j<n;j++)
{
if (a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
cout <<"排序后的顺序为:" << endl;
for (int m=0;m<n;m++)
{cout <<a[m] <<endl;}
return 0;
}

void main()
{
int n;
cout <<"请输入要排序的数的个数:"<<endl;
cin>> n;
int *x;
x=new int[n];
cout <<"请输入要排序的数"<<endl;
for (int y=0;y<n;y++)
cin>>x[y];
px(x,n);
delete []x;
}

#include <iostream>
using namespace std;
int px(int a[],int n) //排序函数
{
int temp;
for (int i=0;i<n-1;i++)
{
for (int j=0;j<n-1;j++)