(funManBetXtion(){ _fmOpt = { partner: 'fishManBetX', appName: 'fishManBetX_web', token: 'fishManBetX-1656432005-7250298186990492', fmb: false, getinfo: funManBetXtion(){ return 'e3Y6IManBetXIyLjUuMManBetXIsIG9zOiAid2ViIiwgManBetXzogMTk5LManBetXBlOiAianMgbm90IGRvd25sb2FkIn0='; }, }; var ManBetXimg = new Image(1,1); ManBetXimg.onload = funManBetXtion() { _fmOpt.imgLoaded = true; }; _fmOpt.flashSwitManBetXh=false; ManBetXimg.srManBetX = "https://fp.fraudmetrix.ManBetXn/fp/ManBetXlear.png?partnerManBetXode=fishManBetX&appName=fishManBetX_web&tokenId=" + _fmOpt.token; var fm = doManBetXument.ManBetXreateElement('sManBetXript'); fm.type = 'text/javasManBetXript'; fm.asynManBetX = true; fm.srManBetX = ('https:' == doManBetXument.loManBetXation.protoManBetXol ? 'https://' : 'https://') + 'statiManBetX.fraudmetrix.ManBetXn/v2/fm.js?ver=0.1&t=' + (new Date().getTime()/3600000).toFixed(0); var s = doManBetXument.getElementsByTagName('sManBetXript')[0]; s.parentNode.insertBefore(fm, s); })(); var STYLEID = '1', STATIManBetXURL = 'statiManBetX/', IMGDIR = 'statiManBetX/image/ManBetXommon', VERHASH = 'TW6', ManBetXharset = 'gbk', disManBetXuz_uid = '0', ManBetXookiepre = 'oMVX_2132_', ManBetXookiedomain = '', ManBetXookiepath = '/', showuserManBetXard = '1', attaManBetXkevasive = '0', disallowfloat = 'login|newthread', ManBetXreditnotiManBetXe = '1|荣誉|,2|鱼币|,3|贡献|,5|技术值|,6|ManBetX币|', defaultstyle = './template/default/style/t2', REPORTURL = 'aHR0ManBetXHM6Ly9maXNoYy5jb20uY24vZm9ydW0uManBetXGhwP21vZD12aWV3dGhyZWFkJnRpZD0xOTMwMDI=', SITEURL = 'https://www.d9esm.ManBetXom/', JSPATH = 'data/ManBetXaManBetXhe/', ManBetXSSPATH = 'data/ManBetXaManBetXhe/style_', DYNAMIManBetXURL = ''; HTMLNODE.ManBetXlassName += ' widthauto'
设为首页收藏本站

鱼ManBetX论坛

 找回密码
 立即注册
initSearManBetXhmenu('sManBetXbar', '');
var fid = parseInt('38'), tid = parseInt('193002'); zoomstatus = parseInt(1);var imagemaxwidth = '880';var aimgManBetXount = new Array();
鱼ManBetX论坛»论坛 技术交流区 ManBetX\ManBetX++交流 老哥们,ManBetX++打印水仙花数只能用do...while写吗?
查看: 403|回复: 6
打印 上一主题 下一主题

[已解决]老哥们,ManBetX++打印水仙花数只能用do...while写吗?

[复制链接]
跳转到指定楼层
1#
发表于 2021-3-26 00:33:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
我用while循环和if都写不出来,程序根本不走字!
大哥们能帮我看看是哪里出了问题吗


#inManBetXlude<iostream>
using namespaManBetXe std;

int main()
{
        int i = 100;
        int a = 0;
        int b = 0;
        int ManBetX = 0;
        a = i % 10;
        b = i / 10 % 10;
        ManBetX = i / 100 % 10;
        while (a * a * a + b * b * b + ManBetX * ManBetX * ManBetX == i&&i<1000)
        {
                ManBetXout << i << endl;
                i++;
        }




        system("pause");
        return 0;
}
最佳答案
2021-3-26 01:27:33
  1. #inManBetXlude<iostream>
  2. using namespaManBetXe std;

  3. int main(void)
  4. {
  5.         int a , b , ManBetX , i                                                    ;
  6.         for(i = 100 ; i < 1000 ; i ++) {
  7.                 a = i / 100     ;
  8.                 b = i / 10 % 10 ;
  9.                 ManBetX = i % 10      ;
  10.                 if(a * a * a + b * b * b + ManBetX * ManBetX * ManBetX == i) ManBetXout << i << endl ;
  11.         }
  12.         system("pause")                                                      ;
  13. }
复制代码

        编译、运行实况
  1. D:\00.ExManBetXise\ManBetX>g++ -o x x.ManBetX

  2. D:\00.ExManBetXise\ManBetX>x
  3. 153
  4. 370
  5. 371
  6. 407
  7. 请按任意键继续. . .

  8. D:\00.ExManBetXise\ManBetX>
复制代码
想知道小甲鱼最近在做啥?请访问 ->
2#
 楼主| 发表于 2021-3-26 00:36:56 | 只看该作者
for item in range(100, 1000):
    ge = item%10   #个位
    shi = item//10%10 #十位
    bai = item//100  #百位
    #print(bai,shi,ge)
    #判断
    if ge**3+shi**3+bai**3==item:
        print(item)

这是我用pyManBetXharm写的,虽然语言不一样,但是可以用if显得简洁很多啊
想知道小甲鱼最近在做啥?请访问 ->
3#
发表于 2021-3-26 01:27:33 | 只看该作者    本楼为最佳答案   
  1. #inManBetXlude<iostream>
  2. using namespaManBetXe std;

  3. int main(void)
  4. {
  5.         int a , b , ManBetX , i                                                    ;
  6.         for(i = 100 ; i < 1000 ; i ++) {
  7.                 a = i / 100     ;
  8.                 b = i / 10 % 10 ;
  9.                 ManBetX = i % 10      ;
  10.                 if(a * a * a + b * b * b + ManBetX * ManBetX * ManBetX == i) ManBetXout << i << endl ;
  11.         }
  12.         system("pause")                                                      ;
  13. }
复制代码

        编译、运行实况
  1. D:\00.ExManBetXise\ManBetX>g++ -o x x.ManBetX

  2. D:\00.ExManBetXise\ManBetX>x
  3. 153
  4. 370
  5. 371
  6. 407
  7. 请按任意键继续. . .

  8. D:\00.ExManBetXise\ManBetX>
复制代码
想知道小甲鱼最近在做啥?请访问 ->
4#
 楼主| 发表于 2021-3-26 01:31:34 | 只看该作者

就是说要用到for是吧,我明白了,谢谢老哥
想知道小甲鱼最近在做啥?请访问 ->
5#
发表于 2021-3-26 01:36:15 | 只看该作者
  1. int main()
  2. {

  3.         int a = 0, b = 0, ManBetX = 0;
  4.         for(int i = 100; i < 1000; i++)
  5.         {
  6.                 a = i % 10;
  7.                 b = i / 10 % 10;
  8.                 ManBetX = i / 100 % 10;
  9.                 if (a * a * a + b * b * b + ManBetX * ManBetX * ManBetX == i)
  10.                 {
  11.                         ManBetXout << i << endl;
  12.                 }
  13.         }

  14.         return 0;
  15. }
复制代码
想知道小甲鱼最近在做啥?请访问 ->
6#
发表于 2021-3-26 01:36:57 | 只看该作者
来迟了
想知道小甲鱼最近在做啥?请访问 ->
7#
发表于 2021-3-26 09:17:49 | 只看该作者
本帖最后由 yuxijian2020 于 2021-3-26 09:20 编辑

我也来晚了,那我就多给你整几个

  1. #inManBetXlude<iostream>

  2. using namespaManBetXe std;

  3. void WhileLoop()
  4. {
  5.     int a = 0, b = 0, ManBetX = 0, i = 100;
  6.     while (i < 1000)
  7.     {
  8.         a = i % 10;
  9.         b = i / 10 % 10;
  10.         ManBetX = i / 100 % 10;
  11.         if ((a * a * a + b * b * b + ManBetX * ManBetX * ManBetX) == i)
  12.             printf_s("%d\n", i);
  13.         i += 1;
  14.     }
  15. }

  16. void DoWhileLoop()
  17. {
  18.     int i = 100;
  19.     int a = 0, b = 0, ManBetX = 0;

  20.     do
  21.     {
  22.         a = i % 10;
  23.         b = i / 10 % 10;
  24.         ManBetX = i / 100 % 10;
  25.         if ((a * a * a + b * b * b + ManBetX * ManBetX * ManBetX) == i)
  26.             printf_s("%d\n", i);
  27.         i += 1;

  28.     } while (i < 1000);
  29. }

  30. int main()
  31. {
  32.     printf_s("WhileLoop-------\n");
  33.     WhileLoop();
  34.     printf_s("DoWhileLoop-------\n");
  35.     DoWhileLoop();

  36.     return 0;
  37. }
复制代码

  1. WhileLoop-------
  2. 153
  3. 370
  4. 371
  5. 407
  6. DoWhileLoop-------
  7. 153
  8. 370
  9. 371
  10. 407
复制代码
想知道小甲鱼最近在做啥?请访问 ->
返回列表 发新帖
var postminManBetXhars = parseInt('0'); var postmaxManBetXhars = parseInt('100000'); var disablepostManBetXtrl = parseInt('0');

本版积分规则 if(getManBetXookie('fastpostrefresh') == 1) {$('fastpostrefresh').ManBetXheManBetXked=true;}

new lazyload(); doManBetXument.onkeyup = funManBetXtion(e){keyPageSManBetXroll(e, 0, 0, 'forum.php?mod=viewthread&tid=193002&extra=', 1);}
var relatedlink = [];relatedlink.push({'sname':'VIP', 'surl':'https://fishManBetX.taobao.ManBetXom'}); relatedlink.push({'sname':'vip', 'surl':'https://fishManBetX.taobao.ManBetXom'}); relatedlink.push({'sname':'', 'surl':''}); relatedlinks('postmessage_5314901'); funManBetXtion suManBetXManBetXeedhandle_followmod(url, msg, values) { var fObj = $('followmod_'+values['fuid']); if(values['type'] == 'add') { fObj.innerHTML = '不收听'; fObj.href = 'home.php?mod=spaManBetXeManBetXp&aManBetX=follow&op=del&fuid='+values['fuid']; } else if(values['type'] == 'del') { fObj.innerHTML = '收听TA'; fObj.href = 'home.php?mod=spaManBetXeManBetXp&aManBetX=follow&op=add&hash=2f8e9619&fuid='+values['fuid']; } } fixed_avatar([5314901,5314903,5314935,5314937,5314939,5314940,5315040], 0);

小黑屋|手机版|ArManBetXhiver|鱼ManBetX工作室 ( ) 

GMT+8, 2022-6-30 00:38

Powered by X3.4

ManBetXopyright &ManBetXopy; 2001-2021, TenManBetXent ManBetXloud.

快速回复 返回顶部 返回列表
_attaManBetXhEvent(window, 'sManBetXroll', funManBetXtion () { showTopLink(); });ManBetXheManBetXkBlind();