爱情错觉歌词:C语言编写程序:输入4个互不相等的实型数,输出其中最大一个.

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/03 10:47:29
要求:1:实数的允许范围为-10^6到10^6,若输入有越界,则给出出错信息.
2:程序要有连续处理的能力,当且仅当输出的4个数全为零时,程序完成.
用while(条件表达式)
谢谢你们的解答.

long int a[5]=0;
int i=0;
do{
while(i<3)
{
cout<<"enter new value";
cin>>a[i++];
if(a[--i]<10000000 &&a[i]>1000000)
cout<<"error!,reenter valid value:"<<endl;
else
{
a[4]=a[i]<a[4]?a[4]:a[i];
i++;
}
if(a[4]==0) /*此处之所以这样写,其实,如果全部输入的是0,那么a[4]肯定是0啦,不信,你去看看第2个循环*/
break;
cout<<"This time the max value of you enterd is:"<<a[4]<<endl;
}
while(3);

实现的主要程序片如下:

float a[6],max=0.0;
int s=0;int t=0;

while(s!=4 && t<5)
{
cin>>a[t];
if(a[t]<10000000 &&a[t]>1000000)
cout<<"error!,reenter valid value:"<<endl;
if (!a[t]) s++;
max=a[t]>max? a[t]:max;

}
cout<<max;