1int main(){
2
3 int a;
4 cin >> a;
5 int check = a;
6 int sum = 0;
7 while(a!=0){
8 int rem = a%10;
9 sum += pow(rem,3); //include cmath
10 a/=10;
11 }
12
13 if(sum==check){
14 cout << "armstrong";
15 } else {
16 cout << "not armstrong";
17 }
18 return 0;
19}
1temp=n;
2while(n>0)
3{
4r=n%10;
5sum=sum+(r*r*r);
6n=n/10;
7}
8if(temp==sum)
9printf("armstrong number ");
10else
11printf("not armstrong number");
12return 0;
1#include <stdio.h>
2#include <stdlib.h>
3#include <math.h>
4
5int cube(int a)
6{
7 int c;
8 c = a*a*a;
9 return c;
10}
11
12int armnum(int *a)
13{
14 int x = *a, n = 0, rem, r = 0;
15 while (x != 0) {
16 x /= 10;
17 n++;
18 }
19 x = *a;
20 while (x != 0) {
21 rem = x % 10;
22 r += cube(rem);
23 x /= 10;
24 }
25 if(r == *a){
26 return 1;
27 }
28}
29
30int main()
31{
32 int a, y;
33 scanf("%d", &a);
34 y = armnum(&a);
35 if(y == 1){
36 printf("It is an Armstrong number.");
37 }
38 else{
39 printf("It is not an Armstrong number.");
40 }
41}
1Numbers -- Armstrong numbers
2Write a method that can check if a number is Armstrong number
3
4Solution:
5public static boolean ArmStrongNumber (int num) {
6int a = 0, b =0, c= num;
7while(num>0){
8 a=num%10;
9 num/=10;
10 b=b+(a*a*a);
11}
12
13if(c==b) {
14return true;
15}
16return false;
17}
1// Armstrong Numbers
21, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748...