int main() { int n; cin>>n>>endl; int a[n]; float b[n]; double c[n]; 这么声明数组为什么不行
#include <iostream> #include <string> using namespace std; int main() { int n; cin>>n>>endl; int a[n]; float b[n]; double c[n]; void sort(int [],int n); void sort(float [],int n); void sort(double [],int n); sort(a,n); sort(b,n); sort(c,n); return 0; }
void sort(int a[],int n) {int i,j,t; for (j=0;n<5;j++) for(i=0;n<5-j;i++) if (a[i]>a[i+1]) {t=a[i];a[i]=a[i+1];a[i+1]=t;} cout<<"输入整型数字:"<<endl; for(i=0;i<5;i++) cout<<a[n]<<" "; cout<<endl; }
void sort(float a[],int n) {int i,j; float t; for (j=0;j<n;j++) for(i=0;i<n-j;i++) if (a[i]>a[i+1]) {t=a[i];a[i]=a[i+1];a[i+1]=t;} cout<<"输入单精度数字:"<<endl; for(i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl; }
void sort(double a[],int n) {int i,j; double t; for (j=0;j<n;j++) for(i=0;i<n-j;i++) if (a[i]>a[i+1]) {t=a[i];a[i]=a[i+1];a[i+1]=t;} cout<<"输入双精度数字:"<<endl; for(i=0;i<5;i++) cout<<a[i]<<" "; cout<<endl; } 要动态声明要这样写 int n; cin>>n>>endl; int* a=new int[n]; float* b=new float[n]; double* c=new double[n]; 改了以后 还显示 error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion) 第6行有错