Search
 
SCRIPT & CODE EXAMPLE
 

CPP

armstrong number in cpp

// armstrong or not

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int num, temp, i, j, rem, sum=0, power=0;

    cout<< "Enter the number: ";
    cin>> num;

    temp = num;

    for(i=1; temp!=0; i++)
    {
        rem = temp % 10;
        for(j=0; j<10;j++)
        {
            if (rem == j)
                power++;
        }
        temp = temp / 10;
    }

    temp = num;

    for(i=1; temp!=0; i++)
    {
        rem = temp % 10;
        sum = sum + pow(rem, power);
        temp = temp / 10;
    }


    if(sum == num)
        cout<< "armstrong" ;
    else
        cout<< "Not armstrong";

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ get environment variable 
Cpp :: C++ std::string find and replace 
Cpp :: how to iterate throguh a string in c++ 
Cpp :: create file c++ 
Cpp :: initialize 2d vector 
Cpp :: cpp std list example 
Cpp :: iterate over 2 vectors c++ 
Cpp :: C++ cin cout 
Cpp :: count bits c++ 
Cpp :: coordinate in 1d array c++ 
Cpp :: check if char in string c++ 
Cpp :: c++ get type name of object 
Cpp :: what is c++ used for 
Cpp :: lutris 
Cpp :: deque c++ 
Cpp :: c++ array rev pointer 
Cpp :: how to sort in descending order in c++ 
Cpp :: To Lower Case leetcode solution in c++ 
Cpp :: c++ casting 
Cpp :: inline function in c++ 
Cpp :: cin getline 
Cpp :: Setting a number of decimals on a float on C++ 
Cpp :: substr in cpp 
Cpp :: if statement c++ 
Cpp :: c++ hello world linux 
Cpp :: how to use custom array in c++ 
Cpp :: how to say hello world in c++ 
Cpp :: how to remove maximum number of characters in c++ cin,ignore 
Cpp :: vector in c++ 
Cpp :: inheritance example in C plus plus 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =