Armstrong Number with Recursion
Write a program to find the given number is Armstrong number or not with the help of a recursive function.
Write a program to find the given number is Armstrong number or not with the help of a recursive function.
Armstrong number is a number that is equal to the sum of digits raised to the power as length of the number.
import java.io.*;
public class armnum
{
static double n;int l;
void armnum(int nn)
{
n=nn;
String str=Double.toString(n);
l=str.length();
}
double sum_pow(double i)
{
if(i==0)
return 0;
else
{
double d=i%10;
double sum=Math.pow(d,l);
return(sum+sum_pow(i/10));
}
}
void isarmstrong()
{
if(sum_pow(n)==n)
System.out.println("armstrong number");
else
System.out.println("not armstrong number");
}
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the number");
double n=Double.parseDouble(br.readLine());
armnum obj=new armnum();
obj.isarmstrong();
}
}Related Posts
Continue learning with these related articles

ISC Practical 2027: Image Editor – Brighten an Image and Find Bright Spots (2-D Array) – Java Program
Fully solved ISC Computer Science Practical 2027 2-D array question: brighten a grayscale image (capping values at 255) and find the bright spots, pixels larger than all four neighbours. Includes a missing bright spot in CISCE’s sample output.

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.