阿姆斯壮数_C ++中的阿姆斯壮编号程序

阿姆斯壮数

Here you will get program for armstrong number in C++.

在这里,您将获得C ++中的Armstrong编号程序。

A number whose sum of digits raised to power n is equal to itself is called armstrong number. Here n is the total digits in the number.

一个数字的幂加到n等于自己的数字称为阿姆斯特朗数。 这里n是数字中的总位数。

For example, 153 is armstrong number as 153 = 1+ 5+ 33 = 1 + 125 +27.

例如,153是阿姆斯壮数,因为153 = 1 3 + 5 3 + 3 3 = 1 + 125 +27。

C ++中的阿姆斯壮编号程序 (Program for Armstrong Number in C++)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int n,m=0,p=0,x,y;
cout<<"Enter any number: ";
cin>>n;
y=n;
while(y!=0){
y=y/10;
p++;
}
y=n;
while(n!=0)
{
x=n%10;
m+=pow(x,p);
n=n/10;
}
if(y==m)
cout<<"The given number is an armstrong number";
else
cout<<"The given number is not an armstrong number";
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include<iostream>
#include<math.h>
using namespace std ;
int main ( )
{
int n , m = 0 , p = 0 , x , y ;
cout << "Enter any number: " ;
cin >> n ;
y = n ;
while ( y != 0 ) {
y = y / 10 ;
p ++ ;
}
y = n ;
while ( n != 0 )
{
x = n % 10 ;
m += pow ( x , p ) ;
n = n / 10 ;
}
if ( y == m )
cout << "The given number is an armstrong number" ;
else
cout << "The given number is not an armstrong number" ;
return 0 ;
}

Output

输出量

Enter any number: 7 The given number is an armstrong number

输入任何数字:7 给定的数字是阿姆斯壮数字

翻译自: https://www.thecrazyprogrammer.com/2012/11/c-program-to-find-whether-number-is.html

阿姆斯壮数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值