本程序包含的两个判断均为过程型的IF,所以还有很大改进算法的空间,比如换成用FOR来循环。
//2002.09.11.this programme shows how to estimate if a num is a negative...
#include <iostream.h>
main()
{
cout<<endl;
cout<<"#####################"<<endl;
cout<<""<<endl;
cout<<"please input 4 nums: "<<endl;
cout<<endl;
long int a,b,c,d;
cout<<"please input a.value: "<<endl;
cin>>a;
cout<<"please input b.value: "<<endl;
cin>>b;
cout<<"please input c.value: "<<endl;
cin>>c;
cout<<"please input d.value: "<<endl;
cin>>d;
cout<<endl;
long int z=0;
if (a<0) ++z;
if (b<0) ++z;
if (c<0) ++z;
if (d<0) ++z;
if (a<b)
{a=b;}
if (a<c)
{a=c;}
if (a<d)
{a=d;}
//else z=c;
//else z=b;
cout<<endl;
cout<<"the big num is: "<<a<<endl;
cout<<"the negative is: "<<z<<endl;
cout<<endl;
cout<<"do you want to exit?"<<endl;
char cc;
cin>>cc;
return 0;
}