Write
a C program to find the nth strong number. or Write a program to
find the nth strong number in C.
Program in C
Code:
/*Write a C program to find
the nth strong number. or Write a program to find the nth strong
number Using C*/
#include <stdio.h>
#include<math.h>
int
main ()
{
int i, rangenumber, num = 1, c = 0, letest = 0, j;
printf ("Enter the Nth value:");
scanf ("%d", &rangenumber);
while (c != rangenumber)
{
int num2 = num;
int num1 = num;
int sum = 0;
int fact = 1;
while (num1 != 0)
{
fact = 1;
int rem = num1 % 10;
num1 = num1 / 10;
for (j = 1; j <= rem; j++)
fact = fact * j;
sum = sum + fact;
}
if (sum == num2)
{
c++;
letest = num;
}
num = num + 1;
}
printf ("%dth strong number is %d", rangenumber, letest);
return 0;
}
Input/Output:
Enter the Nth value:3
3th strong number is 145
Write
a C++ program to find the nth strong number. or Write a program
to find the nth strong number in C++.
Program in C++
Code:
/*Write a C++
program to find the nth strong number. or Write a program
to find the nth strong number using C++*/
#include <iostream>
#include<cmath>
using namespace std;
int
main ()
{
int i, rangenumber, num = 1, c = 0, letest = 0, j;
cout<<"Enter the Nth value:";
cin>>rangenumber;
while (c != rangenumber)
{
int num2 = num;
int num1 = num;
int sum = 0;
int fact = 1;
while (num1 != 0)
{
fact = 1;
int rem = num1 % 10;
num1 = num1 / 10;
for (j = 1; j <= rem; j++)
fact = fact * j;
sum = sum + fact;
}
if (sum == num2)
{
c++;
letest = num;
}
num = num + 1;
}
cout<<rangenumber<<"th strong number is "<<letest;
return 0;
}
Input/Output:
Enter the Nth value:4
4th strong number is 40585
Write
a JAVA program to find the nth strong number. or Write a
program to find the nth strong number in Java.
Program in Java
Code:
/*Write a JAVA
program to find the nth strong number. or Write a program
to find the nth strong number using Java*/
import java.util.Scanner;
public class NthStrongNumber {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int rangenumber, num = 1, c = 0, letest = 0, j;
System.out.println("Enter the Nth value:");
rangenumber=cs.nextInt();
while (c != rangenumber)
{
int num2 = num;
int num1 = num;
int sum = 0;
int fact = 1;
while (num1 != 0)
{
fact = 1;
int rem = num1 % 10;
num1 = num1 / 10;
for (j = 1; j <= rem; j++)
fact = fact * j;
sum = sum + fact;
}
if (sum == num2)
{
c++;
letest = num;
}
num = num + 1;
}
System.out.println(rangenumber+"th strong number is "+letest);
cs.close();
}
}
Input/Output:
Enter the Nth value:
2
2th strong number is 2
Write a PYTHON to find the nth strong number. or Write a program to find the nth strong number in Python.
Program in Python
Code:
'''Write a Python
program to find the nth strong number. or Write a
program to find the nth strong number using Python '''
print("Enter the Nth value:")
rangenumber=int(input())
num = 1
c = 0
letest = 0
while (c != rangenumber):
num2 = num
num1 = num
sum = 0
fact = 1
while (num1 != 0):
fact = 1
rem = num1 % 10
num1 = num1 // 10
for j in range(1,rem+1):
fact = fact * j
sum = sum + fact
if (sum == num2):
c+=1
letest = num
num = num + 1
print(rangenumber,"th strong number is ",letest)
print("Enter the Nth value:")
rangenumber=int(input())
num = 1
c = 0
letest = 0
while (c != rangenumber):
num2 = num
num1 = num
sum = 0
fact = 1
while (num1 != 0):
fact = 1
rem = num1 % 10
num1 = num1 // 10
for j in range(1,rem+1):
fact = fact * j
sum = sum + fact
if (sum == num2):
c+=1
letest = num
num = num + 1
print(rangenumber,"th strong number is ",letest)
Input/Output:
Enter the Nth value:
4
4 th strong number is 40585
0 Comments
Please do not Enter any spam link in the comment box