zoukankan      html  css  js  c++  java
  • 每日一小练——Armstrong数

    上得厅堂,下得厨房,写得代码,翻得围墙。欢迎来到睿不可挡的每日一小练!


    题目:Armstrong数


    内容:

    在三位的正整数中,比如abc,有一些能够满足a^3+b^3+c^3=abc的条件,也就是说各个位数的立方和正好是该数本身,这些数称为Armstrong数。

    是编写一个程序求出全部的三位Armstrong数。


    我的解法:上来没多想,打开vs2013就敲了起来。问题果然非常easy,分分钟就超神。

    。奥。不正确就攻克了。Armstrong数在国内好像就叫做水仙花数,非常多程序设计的课本后面都有这样的类型的思考题,确实非常easy!


    #include <iostream>
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	bool armstrong(int x);
    	for (int i = 100; i <= 999; i++)
    	{
    		if (armstrong(i))
    			cout << i << endl;
    	}
    	getchar();
    	return 0;
    }
    
    bool armstrong(int x) //x应该是一个三位数
    {
    	bool result = false;
    	int bai = x / 100;
    	int shi = (x / 10) % 10;
    	int ge = x % 10;
    	if(x == (bai*bai*bai + shi*shi*shi + ge*ge*ge))
    		result = true;
    	return result;
    }
    

    实验结果:






    欢迎大家增加每日一小练,嘿嘿!

    每天练一练,日久见功夫,加油!


                -End-

    參考文献:《c语言名题精选百则》




    欢迎大家增加每日一小练。嘿嘿。

    每天练一练。日久见功夫,加油!


                -End-

    參考文献:《c语言名题精选百则》


  • 相关阅读:
    multimap-rebgin
    multiset-lower_bound
    multiset-lower_bound
    multimap-max_size
    multimap-max_size
    multimap-find
    最小生成树之prim算法
    最小生成树的邻接矩阵实现
    最短路径:(Dijkstra & Floyd)
    邻接表实现图的储存,遍历
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/6899548.html
Copyright © 2011-2022 走看看