Problem no 4: Armstrong number.

 QUESTION:

 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


ANSWER:


string armstrongNumber(int n){
        int x=n;
        int result=0;
        while(n>0)
        {
           
            int rem =n%10;
            result=result+pow(rem,3);
            n=n/10;
        }
        if(x==result)
        {
            return "Yes";
        }
        else
        {
            return "No";
        }
    }

Comments

Popular posts from this blog

problem 3: given two integers N and M. The problem is to find the number closest to N and divisible by M. If there are more than one such number, then output the one having maximum absolute value.

problem 1: print the table of N.

problem no 60:(problem on the matrix):printing the matrix in snake pattern