Wed Oct 30 2019

Armstrong Number

C++ Programming2013 views

File Name: armstrong-number.cpp

#include<iostream>
using namespace std;

/* Global variable */
int no;
int main() {
	int no, mod, ans;
	cout << "Check the given number is Armstrong or not\n";
	cout << "Enter a number:\n";
	cin >> no;
	
	/* Store value in global variable using scope resolution operator */
	::no = no;

	/* Loop the process using "while loop" */
	while(no != 0) {
		mod = no % 10;
		ans += (mod * mod * mod);
		no = no / 10;
	}

	/* Compare 'ans' with global variable using scope resolution operator */
	if(ans == ::no)
		cout << "It's a Armstrong Number!\n";
	else
		cout << "It's not a Armstrong Number!\n";
	return 0;
}


/* Output */
/* Check the given number is Armstrong or not

Enter a number:
123

It's not a Armstrong Number! */



/* ------------------------------- */


/*
Check the given number is Armstrong or not

Enter a number:
153

It's a Armstrong Number! */

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.