Computer Science, asked by jnavneet594, 9 months ago


A number is said to be neon, if sum of all the digits of square of a number is equal to the
number itself.
Example : Input : 9 It's square 81 = 8+1 = 9 (so 9 is a neon number)
Input : 25 It's square = 625 = 6+2+5 = 13 (so 25 is not a neon number)
Write a program to find and print neon numbers from different numbers. The program
should terminate/stop it's processing when a negative number is given as input. Use for
loop for finding sum of digits and other process.​

Answers

Answered by Equestriadash
15

The following program has been written using Python.

choice = "Y"

while choice == "Y" or choice == 'y':

   num = int(input("Enter a number: "))

   sqn = num**2

   print(sqn, "is the square of the number.")

   if num > 0:

       s = 0

       for i in str(sqn):

           s = s + int(i)

       print(s, "is the sum of the digits in the square.")

       if s == num:

           print(num, "is a Neon number.")

       elif s != num:

           print(num, "is not a Neon number.")

   elif num < 0:

       print("The number you've entered is negative.")

   print()

   choice = input("Would you like to try with a different number? [Y/N]: ")

   print()

Similar questions