# Program to Find nth Armstrong Number

A Number is an Armstrong Number if the sum of cubes of digits of the number is equal to Given Number.

Example:

Given Number=370
sum of cubes of digits=3³+7³+0³=27+343+0=370

Problem statement:-  Program to Find nth Armstrong Number.

Data requirement:-

Input Data:- rangenumber

Output Data:- rangenumber, letest

Additional Data:- cnum, num1, sum, rem

Program in C

Here is the source code of the C Program to Find nth Armstrong Number.

Code:

//Write a Program to Find nth Armstrong Number.
#include <stdio.h>
int
main ()
{
int i, rangenumber, num = 1, c = 0, letest = 0;
printf ("Enter the Nth value:");
scanf ("%d", &rangenumber);

while (c != rangenumber)
{
int num2=num;
int num1=num;
int sum=0;
//reverse of number
while(num1!=0)
{
int rem=num1%10;
num1=num1/10;
sum=sum+rem*rem*rem;//(sum+=pow(rem,3))
}
if(sum==num2)
{
c++;
letest=num;
}
num = num + 1;
}
printf ("%dth Armstrong number is %d", rangenumber, letest);
return 0;
}

Input/Output:
Enter the Nth value:3
3th Armstrong number is 370

Program in C++

Here is the source code of the C++ Program to Find nth Armstrong Number.

Code:

#include <iostream>
using namespace std;
int
main ()
{
int i, rangenumber, num = 1, c = 0, letest = 0;
cout<<"Enter the Nth value:";
cin>>rangenumber;

while (c != rangenumber)
{
int num2=num;
int num1=num;
int sum=0;
while(num1!=0)
{
int rem=num1%10;
num1=num1/10;
sum=sum+rem*rem*rem;
}
if(sum==num2)
{
c++;
letest=num;
}
num = num + 1;
}
cout<<rangenumber<<"th Armstrong number is "<<letest;
return 0;
}

Input/Output:
Enter the Nth value:5
5th Armstrong number is 407

Program in Java

Here is the source code of the Java Program to Find nth Armstrong Number.

Code:

import java.util.Scanner;
public class NthArmstrongNumber {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int  rangenumber, num = 1, c = 0, letest = 0;
System.out.println("Enter Nth number:");
rangenumber=cs.nextInt();

while (c != rangenumber)
{
int num2 = num;
int num1 = num;
int sum = 0;
while (num1 != 0)
{
int rem = num1 % 10;
num1 = num1 / 10;
sum = sum + rem * rem * rem;
}
if (sum == num2)
{
c++;
letest = num;
}
num = num + 1;
}

System.out.println(rangenumber+"th Armstrong number is "+letest);
cs.close();
}
}

Input/Output:
Enter Nth number:
2
2th Armstrong number is 153

Program in Python

Here is the source code of the Python Program to Find nth Armstrong Number.

Code:

rangenumber=int(input("Enter a Nth Number:"))
c = 0
letest = 0
num = 1
while c != rangenumber:
num2 = num
num1 = num
sum = 0
while num1 != 0:
rem = num1 % 10
num1 = num1 // 10
sum = sum + rem * rem * rem
if sum == num2:
c+=1
letest = num

num = num + 1
print(rangenumber,"th Armstrong Number is ",latest)

Input/Output:
Enter a Nth Number:4
4 th Armstrong Number is  371

More:-