• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

水仙花数

武飞扬头像
菠萝21
帮助1

水仙花数是指一个三位数,他的每个位数三次幂等于他本身。例如:153=1^3 5^3 3^3.

for循环实现:

  1.  
    #include<stdio.h>
  2.  
    #include<math.h>
  3.  
    int main()
  4.  
    {
  5.  
    int m,n,i;
  6.  
    scanf("%d%d",&n,&m);
  7.  
    for(i=n;i<=m;i )
  8.  
    {
  9.  
    int a=i/100;
  10.  
    int b=i/10%10;
  11.  
    int c=i%10;
  12.  
    if(i==pow(a,3) pow(b,3) pow(c,3))
  13.  
    {
  14.  
    printf("%d ",i);
  15.  
    }
  16.  
    }
  17.  
    return 0;
  18.  
    }
学新通

  1.  
    #include<stdio.h>
  2.  
    #include<math.h>
  3.  
    int main()
  4.  
    {
  5.  
    int a=0,b=0,c=0;
  6.  
    for(a=1;a<=9;a )
  7.  
    {
  8.  
    for(b=0;b<=9;b )
  9.  
    {
  10.  
     
  11.  
    for(c=0;c<=9;c )
  12.  
    {
  13.  
    if(pow(a,3) pow(b,3) pow(c,3)==a*100 b*10 c)
  14.  
    {
  15.  
    printf("%d ",a*100 b*10 c);
  16.  
    }
  17.  
    }
  18.  
    }
  19.  
    }
  20.  
    return 0;
  21.  
    }
学新通

while循环实现:

  1.  
    #include<stdio.h>
  2.  
    #include<math.h>
  3.  
    int main()
  4.  
    {
  5.  
    int i=100;
  6.  
    int a,b,c;
  7.  
    while(i<=999)
  8.  
    {
  9.  
    a=i/100;
  10.  
    b=i/10%10;
  11.  
    c=i%10;
  12.  
    if(i==pow(a,3) pow(b,3) pow(c,3))
  13.  
    {
  14.  
    printf("%d ",i);
  15.  
    }
  16.  
    i ;
  17.  
    }
  18.  
    return 0;
  19.  
    }
学新通

第一次写博客有什么不对滴地方请大家指正。

万分感谢。

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfjbef
系列文章
更多 icon
同类精品
更多 icon
继续加载