阿姆斯特朗数
来源:互联网 发布:android开发内存优化 编辑:程序博客网 时间:2024/04/28 21:45
/*
功能: 求n(n ≤ 65536)以内的所有阿姆斯特朗数
阿姆斯特朗数:如果一个正整数等于其各个数字的立方和,
则该数称为阿姆斯特朗数(亦称为自恋性数),1除外,
如407 = 4^3+0^3+7^3就是一个阿姆斯特朗数。
原型:
int CalcArmstrongNumber(int n);
输入参数:
int n: n ≤ 65536
返回值:
n以内的阿姆斯特朗数的数量。
*/
#include <stdio.h>int CalcArmstrongNumber(int n){ /*在这里实现功能*/ int a[10]={0}; int num = 0; int i = 0; int count = 0; int temp = 0; int temp1; if(n>=2 && n<=65536)//判断数是不是在范围内 { for(int k=2;k<=n;k++)//要循环判断其以下的数 { temp1=k; while(temp1>9)//求多位数的每一位存在数组里面 { a[i]=temp1%10; temp1=temp1/10; i++; } a[i]=temp1; count=i+1; for(int j=0;j<count;j++)//计算每位数的三次方值再相加 { temp+=a[j]*a[j]*a[j]; } if(temp==k)//进行对比看看是不是阿姆斯特朗数 { printf("%d\n",k); num++; } temp=0;//要复位 count=0; i=0; } } return num;}void main(){ int n; printf("请输入数值n:"); scanf_s("%d",&n,10); printf("\n%d以下总的有%d的阿姆斯特朗数",n,CalcArmstrongNumber(n)); getchar(); getchar();}
0 0
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数。。。。
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数
- 阿姆斯特朗数--char3
- 阿姆斯特朗数 C++
- Android,listview分割线,样式
- Cocos2d – useful tools
- Android 仿电视关闭的退出效果
- .net
- Android,长按发送语音,简单模拟微信长按语音发送效果
- 阿姆斯特朗数
- android报错记录及解决--Bitmap加载时,报bitmap size exceeds VM budget
- BUG笔记:Win XP IE8下HTML Parsing Error: Unable to modify the parent container element before the child
- My share @company praci
- 作为程序员,2014年应该学哪些技术
- Android 获取当前系统时间
- AJAX跨域的解决方案
- Quartz SchedulerFactoryBean异常--Spring自动装配惹的祸
- Java转型(向上或向下转型)