首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VC >

請见见這個簡單的C程序

2012-12-17 
請看看這個簡單的C程序vectorint numint temp0int max0,min0while(cintemp){num.push_back (tem

請看看這個簡單的C程序
       vector<int> num; 
        int temp=0; 
        int max=0,min=0; 
        while(cin>>temp) 
                {num.push_back (temp); 
 sort(num.begin (),num.end ()); 
                 max=num[num.size ()-1]; 
                 min=num[0]; 
 cout<<"the temp is:"<<temp<<endl;
 cout<<"the min is:"<<min<<endl;
 cout<<"the max is:"<<max<<endl;
                 if(temp<min) 
                         cout<<"the samlest so far:"<<temp<<'\n'; 
                 else if(temp>max) 
                         cout<<"the largest so far:"<<temp<<'\n'; 
        } 

如上:程序的意思很明了,前面temp、min和max的值都是對的。但是程序始終都不進入if分支,不知這是什么原因?求解。
[解决办法]
1、temp==min Or temp==max 

   即使为中间值 temp不会小于min;temp也不会大于max
[解决办法]

引用:
1、temp==min Or temp==max 

  即使为中间值 temp不会小于min;temp也不会大于max

這中情況只會出現在輸入第一個數的時候啊,當輸入的數多的時候,后面的情況會進入if判斷才對啊。
[解决办法]
该回复于2011-11-24 13:37:42被版主删除
[解决办法]
lz 逻辑混乱
[解决办法]
temp与min,max二个值的关系只能是temp=min,temp=max,不可能出现temp<min,temp>max情况,当然不会进入if判断,你自己输入几个数据看看就知道了,temp和min,max的关系

热点排行