zoukankan      html  css  js  c++  java
  • 武汉科技大学ACM :1005: C语言程序设计教程(第三版)课后习题6.6

    Problem Description

    打印出所有"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该本身。 例如:153是一个水仙花数,因为153=1^3+5^3+3^3。 Output:

    153

    ???

    ???

    ???

    Input

    Output

    所有的水仙花数,从小的开始。 每行一个

    Sample Input

    Sample Output

     1 #include<stdio.h>
     2 
     3 #include<math.h>
     4 
     5  
     6 
     7 int main()
     8 
     9 {
    10 
    11          int i;
    12 
    13          for(i=100;i<1000;i++)
    14 
    15                    if(i==pow(i/100,3)+pow(i%100/10,3)+pow(i%10,3))
    16 
    17                             printf("%d
    ",i);
    18 
    19                    getchar();
    20 
    21                    return 0;
    22 
    23 }

    其他代码:

     1 #include<stdio.h>
     2 int flower(int n)
     3 {
     4     if(n>0){
     5         int m=n%10;
     6         int sum=m*m*m;
     7         return sum+flower(n/10);
     8     }
     9     return 0;
    10 }
    11 int main()
    12 {
    13     int i;
    14     for(i=100;i<1000;i++)
    15         if(i==flower(i))
    16             printf("%d
    ",i);
    17 }
  • 相关阅读:
    顺时针
    true
    td
    确定删除
    on("submit",)
    float:right
    css中:hover空格
    磁盘恢复
    一、报表
    二、实践与视频解决方案
  • 原文地址:https://www.cnblogs.com/liuwt365/p/4154138.html
Copyright © 2011-2022 走看看