level 1
#include <iostream>
using namespace std;
void main()
{
float str[7];
float *p;
int i;
for(i=0;i<7;i++)
{
cin>>str[i];
}
for(int a=0;a<7;a++)
{
i=0;
p=str;
while (i<7)
{
if (*p<=str[i+1])
{
*p=str[i+1];
}
i++;
}
cout<<*p<<" ";
*p=0;
}
}
输出不是我要的结果 看一下
2009年12月07日 08点12分
1
level 1
比如输入:1 2 3 4 5 6 7
输出的是 7 7 7 7 7 7 7
2009年12月07日 08点12分
2
level 0
#include<iostream>
using namespace std;
class deal
{
private:
int a[100],n,i,j,t;
public:
input()
{
cout<<"请输入,数组的个数,但小于100"<<endl;
cin>>n;
cout<<"输入"<<n<<"个整数"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
}
Deal()
{
for(j=0;j<n-1;j++)
for(i=0;i<n-j-1;i++)
if(a[i]<a[i+1])
{
t=a[i];
a[i]=a[i+1];
a[i+1]=t;
}
for(i=0; i<n;i++)
cout<<" "<<a[i];
cout<<endl;
}
};
int main()
{
deal A;
A.input();
A.Deal();
}
2009年12月07日 10点12分
3
level 0
你为什么用指针呢?
你的
*p=str[i+1];有问题
p=&str[0],所以*p=str[0]
所以你一直在操作str[0]
建议以熟练冒泡后再尝试用指针
2009年12月09日 13点12分
7
level 0
3楼的为什么是n-1?加入n=20,那么不是只循环了19次?输出19个数?还有那个输出的for语句应该写在Deal()下面吧。
2009年12月11日 07点12分
9