Program in C and C++ to check a given number is Armstrong or not Using recursive function
C Program
#include<iostream> using namespace std; int isArmstrong(int n) { if( n == 0) return 0; else return (((n % 10) * (n % 10) * (n % 10)) + isArmstrong(n / 10)); } int main() { int n; cout<<"Enter a number :- "; cin>>n; if(isArmstrong(n) == n) cout<<n<<" is Armstrong number."; else cout<<n<<" is not Armstrong number."; return 0; }
C++ Program
#include<stdio.h> int isArmstrong(int n) { if( n == 0) return 0; else return (((n % 10) * (n % 10) * (n % 10)) + isArmstrong(n / 10)); } int main() { int n; printf("Enter a number :- "); scanf("%d",&n); if(isArmstrong(n) == n) printf("%d is Armstrong number.",n); else printf("%d is not Armstrong number.",n); return 0; }
Output :-
Recursive function
- Program in C and C++ to print reverse of a given number using recursive function
- Program in C and C++ to print reverse of a given string using recursive function
- Program in C and C++ to print Nth natural numbers in reverse order using recursive function
- Program in C and C++ to find sum of digits of a given number using recursive function
- Program in C and C++ to find sum of nth numbers Using recursive function
0 Comments