标题:求解释啊,为何觉得IF没一点作用
只看楼主
a99875984
Rank: 2
等 级:论坛游民
帖 子:188
专家分:24
注 册:2012-2-11
结帖率:94.64%
已结贴  问题点数:20 回复次数:3 
求解释啊,为何觉得IF没一点作用
程序代码:
//1-9 9个数字,33组合,第三个数为第二个的两倍,第一个的三倍
#include <iostream>
using namespace std;
void fun()
{
    int one,two,three;
    int b[10]={0,0,0,0,0,0,0,0,0,0};
    for(one=123;one<=333;one++)
    {
        three=3*one;
        two=2*one;
        if(one%10!=0&&one/10%10!=0&&one/100!=0&&two%10!=0&&two/10%10!=0&&two/100!=0&&three%10!=0&&three/10%10!=0&&three/100!=0)
        {
            b[(one%10)]=one%10;
            b[(one/100)]=one/100;
            b[((one/10)%10)]=((one/10)%10);
            b[(two%10)]=two%10;
            b[((two/10)%10)]=(two/10)%10;
            b[(two/100)]=two/100;
            b[(three%10)]=three%10;
            b[((three/10)%10)]=(three/10)%10;
            b[(three/100)]=three/100;
            if(b[0]==0&&b[1]==1&&b[2]==2&&b[3]==3&&b[4]==4&&b[5]==5&&b[6]==6&&b[7]==7&&b[8]==8&&b[9]==9)
                cout<<one<<" "<<two<<" "<<three<<" "<<"符合条件"<<endl;
        }
    }
}
int main()
{
    fun();
    return 0;
}

请问下为何觉得IF条件没发挥作用,去掉IF,只是少了2组数据,这是什么情况哈?
还有在数组里,如果数组下标是0,减1会怎么样哈?


[ 本帖最后由 a99875984 于 2012-10-8 18:04 编辑 ]
搜索更多相关主题的帖子: include one fun 
2012-10-08 18:00
风之子MIKEY
Rank: 3Rank: 3
来 自:江西省抚州市
等 级:论坛游侠
帖 子:39
专家分:108
注 册:2012-9-25
得分:20 
你的B[10]数组在执行完次循环后未重新设置初值。
void fun()
{
    int one,two,three;
    int b[10]={0,0,0,0,0,0,0,0,0,0};
    for(one=123;one<=333;one++)
    {
        three=3*one;
        two=2*one;
        if(one%10!=0&&one/10%10!=0&&one/100!=0&&two%10!=0&&two/10%10!=0&&two/100!=0&&three%10!=0&&three/10%10!=0&&three/100!=0)
        {
            b[(one%10)]=one%10;
            b[(one/100)]=one/100;
            b[((one/10)%10)]=((one/10)%10);
            b[(two%10)]=two%10;
            b[((two/10)%10)]=(two/10)%10;
            b[(two/100)]=two/100;
            b[(three%10)]=three%10;
            b[((three/10)%10)]=(three/10)%10;
            b[(three/100)]=three/100;
            if(b[0]==0&&b[1]==1&&b[2]==2&&b[3]==3&&b[4]==4&&b[5]==5&&b[6]==6&&b[7]==7&&b[8]==8&&b[9]==9)
                cout<<one<<" "<<two<<" "<<three<<" "<<"符合条件"<<endl;
            b[0]=0;
            b[1]=0;
            b[2]=0;
            b[3]=0;
            b[4]=0;
            b[5]=0;
            b[6]=0;
            b[7]=0;
            b[8]=0;
            b[9]=0;            
        }
    }
}
不知对否未验证!
2012-10-08 18:57
a99875984
Rank: 2
等 级:论坛游民
帖 子:188
专家分:24
注 册:2012-2-11
得分:0 
回复 2楼 风之子MIKEY
恩,谢谢了,就是没初始化,谢谢了,但还是想问下,当数组的下标为0时,再将下标减1会怎么样哈?
2012-10-08 21:31
风之子MIKEY
Rank: 3Rank: 3
来 自:江西省抚州市
等 级:论坛游侠
帖 子:39
专家分:108
注 册:2012-9-25
得分:0 
得不到你想要的结果,得到的值也不确定。
2012-10-08 22:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382722-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053653 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved