小白求助大神,千万不要飘过啊
c++吧
全部回复
仅看楼主
level 5
Daphnis5 楼主
求问这个程序的调用函数中 a 为什么在VS2010中会提示未定义,明明主函数里就定义了的啊?请大神指出错误和该怎么改,小弟先谢过了
#include <iostream>
using namespace std;
void input_arr(int *,int);
void sort(int *,int);
void output_arr(int *,int);
void main()
{
int a[100],*p,n;
p=a;
cout<<"Please input n:";
cin>>n;
input_arr(p,n);
sort(p,n);
output_arr(p,n);
cout<<endl;
}
void input_arr(int *p,int n)
{
for(p=a;p<a+n;p++) 这一行中的 a 未定义
cin>>*p;
return;
}
void sort(int *p,int n)
{
int temp;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(p+i>p+j) temp=*(p+i),*(p+i)=*(p+j),*(p+j)=temp;
else continue;
return;
}
void output_arr(int *p,int n)
{
cout<<"sorted:";
for(p=a;p<a+n;p++) 这一行中的 a 未定义
cout<<*p<<" ";
return;
}
2013年12月21日 15点12分 1
level 13
局部变量,全局变量……
//@_@眼熟我就粉我吧……
2013年12月21日 15点12分 2
level 13
//微调,没看出楼主要做什么……
#include <iostream>
using namespace std;
void input_arr(int *,int *, int);
void sort(int *, int);
void output_arr(int *,int *, int);
int main()
{
int a[100], *p, n;
p = a;
cout << "Please input n:";
cin >> n;
input_arr(a,p, n);
sort(p, n);
output_arr(a,p, n);
cout << endl;
}
void input_arr(int *a,int *p, int n)
{
for (p = a; p < a + n; p++)
cin >> *p;
return;
}
void sort(int *p, int n)
{
int temp;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (p + i > p + j)
temp = *(p + i), *(p + i) = *(p + j), *(p + j) = temp;
else
continue;
return;
}
void output_arr(int *a,int *p, int n)
{
cout << "sorted:";
for (p = a; p < a + n; p++)
cout << *p << " ";
return;
}
//﹏﹏妈妈说,贴代码不能跟小尾巴♡♥♡
//@_@眼熟我就粉我吧……
2013年12月21日 15点12分 3
就是用指针来写n个数排序啊
2013年12月22日 05点12分
level 13
//是这意思?
#include <iostream>
using namespace std;
void input_arr(int *, int *, int);
void sort(int *, int);
void output_arr(int *, int *, int);
int main()
{
int a[100], *p, n;
p = a;
cout << "Please input n:";
cin >> n;
input_arr(a, p, n);
p = a ;
sort(p, n);
output_arr(a, p, n);
cout << endl;
}
void input_arr(int *a, int *p, int n)
{
for (p = a; p < a + n; p++)
cin >> *p;
return;
}
void sort(int *p, int n)
{
int temp;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (*(p + i) > *(p + j))
{
temp = *(p + i), *(p + i) = *(p + j), *(p + j) = temp;
printf("asd%d\n", *(p + j));
}
else
continue;
return;
}
void output_arr(int *a, int *p, int n)
{
cout << "sorted:";
for (p = a; p < a + n; p++)
cout << *p << " ";
return;
}
//﹏﹏妈妈说,贴代码不能跟小尾巴♡♥♡
//@_@眼熟我就粉我吧……
2013年12月21日 16点12分 4
灰常感谢,粉一个
2013年12月22日 05点12分
level 1
在void input_arr(int *,int)声明中,加上一项int *就行了,然后调用时加上实参a
2013年12月21日 16点12分 5
谢了,就是这样
2013年12月22日 05点12分
1