Armstrong Numbers | Practice | GeeksforGeeks

For a given 3 digit number, find whether it is armstrong number or not. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. Return "Yes" if it is a armstrong number else return "No".
NOTE: 371 is an Armstrong number since 33 + 73 + 13 = 371

Example 1:
Input: N = 153
Output: "Yes"
Explanation: 153 is an Armstrong number
since 13 + 53 + 33 = 153.
Hence answer is "Yes".

Example 2:
Input: N = 370
Output: "Yes"
Explanation: 370 is an Armstrong number
since 33 + 73 + 03 = 370.
Hence answer is "Yes".

Your Task:  
You dont need to read input or print anything. Complete the function armstrongNumber() which takes n as input parameter and returns "Yes" if it is a armstrong number else returns "No"..

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
100 ≤ n <1000
0
abhitan1413 hours ago
string armstrongNumber(int n){       // code here       int rem,sum = 0,real;       real = n;       while(n)       {           rem = n%10;           sum += (rem*rem*rem);           n /= 10;       }       if(sum == real)       {           return "Yes";       }       else       {           return "No";       }   }
0
abhikeshz0kb2 weeks ago
    string armstrongNumber(int n){
        // code here
        int temp=n,rev=0;
        rev+=pow(temp%10,3);temp=temp/10;
                rev+=pow(temp%10,3);temp=temp/10;
                        rev+=pow(temp%10,3);
        if(rev==n)
        return "Yes";else return "No";
    }
0
dhirajhg9872 weeks ago
class Solution { public:   string armstrongNumber(int n){       int rem,sum=0,real;       real=n;       while(n!=0)       {           rem=n%10;           sum=sum+rem*rem*rem;           n=n/10;       }       if(sum==real)       {           cout<<"Yes";       }       else       {           cout<<"No";       }          }};
0
shobhitgautam19993 weeks ago
//User function Template for Javaclass Solution {   static String armstrongNumber(int n){       int original = n;       int rem = 0;       int duplicate = n;       int count =0;       double sum=0;              while(original !=0)        {           original = original/10;           count = count+1;        }              while(duplicate !=0)        {           rem = duplicate%10;           duplicate = duplicate/10;           sum = sum + Math.pow(rem,count);       }       if(sum == n)       {           return ("Yes");       }       else       {           return ("No");       }   }}
0
mizanurhasan3 weeks ago
   #JavaScript
 
let number=n;       let armStrong=0;       while(number!=0){           var x=number%10;           armStrong+=x*x*x;                      number=parseInt(number/10);       }      if(armStrong===n){          return "Yes";      }else{          return "No";      }
0
dakshskrm113 weeks ago
//This one is in O(1) as expected
string armstrongNumber(int n){       // code here       int a=n;       int num=0;       int i=1;       string s1="No";       string s2="Yes";              num+=pow(n%10,3);       n=n/10;              num+=pow(n%10,3);       n=n/10;              num+=pow(n%10,3);       n=n/10;              if(n||a==num){           return s2;       }       return s1;
 
// I always welcome corrections and optimisations
0
au00ay4 weeks ago
// code here       int r,sum=0,temp;       temp=n;       while(n>0)       {           r=n%10;           sum=sum+(r*r*r);           n=n/10;       }       if(temp==sum)       cout<<"Yes";       else       cout<<"No";
0
rumi1w8ry1 month ago
def armstrongNumber (ob, n):       # code here        n =str(n)       sum_num = 0       for i in n:           cube = int(i)**3           sum_num +=cube       n = int(n)       if sum_num == n:           return "Yes"       return "No"
0
jitendraprasadmahato1 month ago
 string armstrongNumber(int n){       // code here              //according to armstrong number concept,       // For example, 0, 1, 153, 370, 371, 407 are three-digit Armstrong numbers        //and, 1634, 8208, 9474 are four-digit Armstrong numbers       int sum=0,digit=0,num=n,rem=0;             while(num>0){           digit++;           num/=10;      }              num=n;       while(num>0){           rem = num%10;                      if(rem!=0){               sum = sum + pow(rem,digit);           }           num/=10;       }              if(sum == n){           return "Yes";       }else{           return "No";       }   }
0
rb0012 months ago
O(1) time complexity;
O(1) space 
class Solution { public:   string armstrongNumber(int n){       // code here
// Code By : Rahul Bisht         int a=n%10,b= (n/10)%10,c = n/100;       if(a*a*a + b*b*b +c*c*c == n)           return "Yes";       else           return "No";   }};
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested 
                                    against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code.
                                    On submission, your code is tested against multiple test cases consisting of all
                                        possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as
                                        the final solution code.
You can view the solutions submitted by other users from the submission tab.
Make sure you are not using ad-blockers.
Disable browser extensions.
We recommend using latest version of your browser for best experience.
Avoid using static/global variables in coding problems as your code is tested 
                                against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases in coding problems does not guarantee the 
                                correctness of code. On submission, your code is tested against multiple test cases
                                    consisting of all possible corner cases and stress constraints.