阿姆斯壮数
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 = 13 + 53 + 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
阿姆斯壮数