C++ Programming
Armstrong Number
C plus plus for Armstrong number with scope resolution operator
By Geekboots
10/30/2019
0 views
armstrong-number.cppCPP
#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! */cppc plus plusArmstrong numberscope resolution operator