Find out all Neon numbers present within a given range

A Number is a Neon Number if the sum of digits of square of the number is equal to the number itself.

Example:

               Given Number=9
               square of 9=9*9=81
               sum of digits of square=8+1=9
                                          
Problem statement:-  Program to Find out all Neon numbers present within a given range

Data requirement:-

   Input Data:- range1, range2

   Output Data:- i, range1, range2

   Additional Data:- num1, sum, rem, sqr

Program in C

Here is the source code of the C Program to Find out all Neon numbers present within a given range.

Code:

//Neon Number in range
#include<stdio.h>
int main()
{
    int range1,range2,i;
    printf("Enter a range:");
    scanf("%d %d",&range1,&range2);
    printf("Neon numbers between %d and %d are: ",range1,range2);
    for(i=range1;i<=range2;i++)
    {
   int sqr=i*i;
     //Sum of digit
    int sum=0,rem;
    while(sqr!=0)
    {
        rem=sqr%10;
        sum+=rem;
        sqr/=10;
    }

   if(sum==i)
    printf("%d ",i);
}
}

Input/Output:
Enter a range:1
5
Neon numbers between 1 and 5 are: 1

Program in C++

Here is the source code of the C++ Program to Find out all Neon numbers present within a given range.

Code:

#include<iostream>
using namespace std;
int main()
{
    int range1,range2,i;
    cout<<"Enter a range:";
    cin>>range1;
    cin>>range2;
    cout<<"Neon numbers between "<<range1<<" and "<<range2<<" are: ";
    for(i=range1;i<=range2;i++)
    {
    int sqr=i*i;
     //Sum of digit
    int sum=0,rem;
    while(sqr!=0)
    {
        rem=sqr%10;
        sum+=rem;
        sqr/=10;
    }

   if(sum==i)
    cout<<i<<" ";
}
}

Input/Output:
Enter a range:1
10
Neon numbers between 1 and 10 are: 1 9

Program in Java
  
Here is the source code of the Java Program to Find out all Neon numbers present within a given range.

Code:

import java.util.Scanner;
public class FindNeonNumbersInRange {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
      int range1,range2;
      System.out.println("Enter a range:");
      range1=cs.nextInt();
      range2=cs.nextInt();
      System.out.println("Neon numbers between "+range1+" and "+range2+" are: ");
      for(int i=range1;i<=range2;i++)
      {
      int sqr=i*i;
         //Sum of digit
        int sum=0,rem;
        while(sqr!=0)
        {
            rem=sqr%10;
            sum+=rem;
            sqr/=10;
        }
      if(sum==i)
      System.out.print(i+" ");
      }
      cs.close();
}
}

Input/Output:
Enter a range:
1
1000
Neon numbers between 1 and 1000 are: 
1 9 

Program in Python
  
Here is the source code of the Python Program to Find out all Neon numbers present within a given range.

Code:

print("Enter a range:")
range1=int(input())
range2=int(input())
print("Neon numbers between ",range1," and ",range2," are: ")
for i in range(range1,range2+1):
    sqr =i*i
    # Sum of digit
    sum = 0
    while sqr != 0:
        rem = sqr % 10
        sum += rem
        sqr //= 10

    if sum == i:
        print(i,end=" ")

Input/Output:
Enter a range:
5
9000
Neon numbers between  5  and  9000  are: 



More:-

C/C++/Java/Python Practice Question 

Post a Comment

2 Comments

Please do not Enter any spam link in the comment box