Follow This Blog For more... 😊

Check Given number is an Armstrong number or not? using C++.

Check Given number is an Armstrong number or not? using C++.

CODE:

 
   #include<iostream>
    using namespace std;

    main()
    {
        int n,temp,sum=0,remainder;
       
        cout<<"Enter the number:";cin>>n;
       
        temp=n;
        while(n>0)
        {
            remainder=n%10;
            sum=sum+remainder*remainder*remainder;
            n=n/10;
        }
        if(sum==temp)
        {
            cout<<temp<<" is an armstrong number";
        }
        else
        {
            cout<<temp<<" is not an armstrong number";
        }
    }


OUTPUT:




Comments

Popular Posts