帮忙编个程序吧 急

来源:百度知道 编辑:UC知道 时间:2024/05/24 19:57:30
3.从数组a[N]中顺序查找出比x值大的所有元素并显示出来,其中x由用户输入。例如:
#include<iostream.h>
const int N=7;
void main()
{
double w[N]={2.6,7.3,4.2,5.4,6.2,3.8,1.4};
。。。。。。

}
例如:
请输入一个实数:5
比5大的数有:
w[1]=7.3
w[3]=5.4
w[4]=6.2

再如:
请输入一个实数:8
比8大的数不存在

//这个简单,我给你写吧.如下:
#include<iostream.h>
const int N=7;
void main()
{
int flag=1;
double x;
double w[N]={2.6,7.3,4.2,5.4,6.2,3.8,1.4};
cout<<"请输入x的值:";
cin>>x;
for(int i=0;i<N;i++)
{
if(x<w[i])
{
cout<<w[i]<<endl;
flag=0;
}
}
if(flag)cout<<"比"<<x<<"大的数不存在"<<endl;
}

#include<iostream.h>

#include<string>

const int N=7;
void main()
{
double w[N]={2.6,7.3,4.2,5.4,6.2,3.8,1.4};
cout<<"请输入一个实数:";
int iInput;
cin>>iInput;

int i=0;
string sOutput="比" + iInput + "大的数有:\n"

for(i=0;i<8;i++)
{
if (w[i]>iInput) sOutput+="w[" + i + "]=" + w[i] + "\n";
}

if (sOutput=="比大的数有:\n") sOutpu