C++ Online Compiler
Example: Armstrong Number in C++ using Recursion
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Armstrong Number in C++ using Recursion #include <bits/stdc++.h> #include <cmath> using namespace std; // This function will check input number is Armstrong or not // This will work recursively int CheckArmstrong(int p) { if (p > 0) return (pow(p %10, 3) + CheckArmstrong(p / 10)); } // It's the driver function int main() { int x; // To store the input number cout << "-----Enter the integer number-----\n"; cin >> x; // It will produce the final output if ((int) CheckArmstrong(x) == x) cout << x << " is an Armstrong number.\n"; else cout << x << " is not an Armstrong number.\n"; return 0; }
311
Output
Clear
ADVERTISEMENTS