Neon Number
What is Neon number ?
9 => 81
9 <= 8+1
neon number : There are only three neon numbers in the range of 0 to 100,000: 0, 1, and 9.
Python
no = int(input("enter a neon number to check : "))
sqr= no*no
def neon(sqr):
SumOfNum=0
while sqr>0:
SumOfNum = sqr%10 + SumOfNum
sqr=sqr//10
return SumOfNum
if no==neon(sqr):
print("its a neon")
else :
print("not neon")
java
import java.util.Scanner;
public class NeonNumber {
public static int neon(int sqr) {
int sumOfNum = 0;
while (sqr > 0) {
sumOfNum = sqr % 10 + sumOfNum;
sqr = sqr / 10;
}
return sumOfNum;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("enter a neon number to check : ");
int no = scanner.nextInt();
int sqr = no * no;
if (no == neon(sqr)) {
System.out.println("its a neon");
} else {
System.out.println("not neon");
}
scanner.close();
}
}
Strong number
145 <----------------
5! --->| 120 |
4! --->| 24 |
1! --->| 1 + |
--------- |
145 --------
---------
-> Strong Numbers are the numbers whose sum of factorial of digits is equal to the original number. Given a number, check if it is a Strong Number or not.
python
def fact(num):
fact = 1
while num>0:
fact = fact * num
num-=1
return fact
given = int(input("enter a Strong Number to Check : "))
copyOgGiven = given
result = 0
while given>0:
result = result + fact(given%10)
given = given //10
#print (result)
if copyOgGiven == result:
print ("its strong number")
else:
print("not strong number")
java
import java.util.Scanner;
public class StrongNumber {
public static int fact(int num) {
int fact = 1;
while (num > 0) {
fact = fact * num;
num--;
}
return fact;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("enter a Strong Number to Check : ");
int given = scanner.nextInt();
int copyOgGiven = given;
int result = 0;
while (given > 0) {
result = result + fact(given % 10);
given = given / 10;
}
if (copyOgGiven == result) {
System.out.println("its strong number");
} else {
System.out.println("not strong number");
}
scanner.close();
}
}
Perfect Number
->Perfect numbers are positive integers that equal the sum of their proper divisors, excluding the number itself. For example, 6 is a perfect number because its proper divisors (1, 2, and 3) add up to 6
6 - Divisors are 1,2,3
1+2+3 = 6
Python
givenNum = int(input("enter a perfect number to check : "))
start = 1
result = 0
while (start<=givenNum//2):
if givenNum%start == 0 :
result+=start
start+=1
if (result == givenNum):
print("it's perfect number")
else:
print("not a perfect number")
java
import java.util.Scanner;
public class PerfectNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("enter a perfect number to check : ");
int givenNum = scanner.nextInt();
int start = 1;
int result = 0;
while (start <= givenNum / 2) {
if (givenNum % start == 0) {
result += start;
}
start++;
}
if (result == givenNum) {
System.out.println("it's perfect number");
} else {
System.out.println("not a perfect number");
}
scanner.close();
}
}
Top comments (0)