To check that enter number is Armstrong or not. (Armstrong no if 3^3 + 7^3 + 1^3 = 371 then 371 is a Armstrong no)

#include <iostream>
using namespace std;

void main ()
{

cout<<"Please enter the number here: ";
int number;
cin>>number;

int number1=number;

int d=1;
int cube;
int sum=0;
while (number >=1 )
{

d=number%10; // for get the digit of number
cube=d*d*d; // for getting the cube
sum=cube+sum; // for get the sum
number=number/10; // for reduce the numeber

}
if (sum==number1)
cout<<"The number is Armstrong"<<endl;
else
cout<<"The number is not Armstrong"<<endl;

}

Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System