2007/04/25 | 这段代码加了一个判断,可以列出所输入的数一共有几个负数
类别(计算机与编程) | 评论(0) | 阅读(3) | 发表于 15:18

本程序包含的两个判断均为过程型的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;

}

0

评论Comments

日志分类
首页[666]
计算机与编程[133]
EMU[40]
UFOs[24]
房产[127]
音乐[13]
LOG[0]
经济[120]
影视[3]
物理[7]
数学[8]
社会[105]
职场[9]
生物医学[18]
生活[59]