#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>
using namespace std;
bool isArmstrong(int n);
int reversNumber(int n);
void isReversedArmstrong(int n);
int main()
{
cout << "Enter first integer: ";
int n1;
cin >> n1;
isReversedArmstrong(n1);
}
bool isArmstrong(int n)
{
int temp = 0,armstrong, total = 0;
armstrong = n;
while (armstrong != 0)
{
temp = armstrong % 10;
total += pow(temp, 3);
armstrong /= 10;
}
if (total == n)
return true;
else
return false;
}
int reversNumber(int n)
{
int reverse = 0, rem = 0;
while (n != 0)
{
rem = n % 10;
reverse = reverse * 10 + rem;
n /= 10;
}
return reverse;
}
void isReversedArmstrong(int n)
{
if (isArmstrong(n))
{
if(isArmstrong(reversNumber(n)))
cout << "the Reversed "<< reversNumber(n)<<" number IS an Armstrong number ";
else
cout << "the Reversed " << reversNumber(n) << " number is NOT Armstrong number ";
}
else
cout << "the number entered is NOT Armstrong number ";
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter