Número de neón

Un número de neón es un número donde la suma de los dígitos del cuadrado del número es igual al número. La tarea es verificar e imprimir números de neón en un rango.

Ejemplos: 

C++

// C/C++ program to check and print
// Neon Numbers upto 10000
#include <iostream>
using namespace std;
#include <math.h>
 
int checkNeon(int x)
{
    // storing the square of x
    int sq = x * x;
 
    // calculating the sum of digits
    // of sq
    int sum_digits = 0;
    while (sq != 0) {
        sum_digits = sum_digits + sq % 10;
        sq = sq / 10;
    }
    return (sum_digits == x);
}
 
// Driver Code
int main(void)
{
    // Printing Neon Numbers upto 10000
    for (int i = 1; i <= 10000; i++)
        if (checkNeon(i))
            cout << i << " ";   
}

Java

// Java program to check and print
// Neon Numbers upto 10000
import java.io.*;
 
class GFG {
    // function to check Neon Number
    static boolean checkNeon(int x)
    {
        // storing the square of x
        int sq = x * x;
 
        // calculating the sum of digits
        // of sq
        int sum_digits = 0;
        while (sq != 0) {
            sum_digits = sum_digits + sq % 10;
            sq = sq / 10;
        }
        return (sum_digits == x);
    }
 
    // Driver Code
    public static void main(String args[])
                        throws IOException
    {
        // Printing Neon Numbers upto 10000
        for (int i = 1; i <= 10000; i++)
            if (checkNeon(i))
                System.out.print(i + " ");       
    }
}
// This code is contributed by Nikita Tiwari.

Python

# Python program to check and print
# Neon Numbers upto 10000
 
# function to check Neon Number
def checkNeon (x) :
    # storing the square of x
    sq = x * x
     
    # calculating the sum of digits
    # of sq
    sum_digits = 0
    while (sq != 0) :
        sum_digits = sum_digits + sq % 10
        sq = sq / 10
     
    return (sum_digits == x)
 
# Driver Code
 
i = 1
# Printing Neon Numbers upto 10000
while i <= 10000 :
    if (checkNeon(i)) :
        print i,
    i = i + 1
 
# This code is contributed by Nikita Tiwari.

C#

// C# program to check and print
// Neon Numbers upto 10000
using System;
 
class GFG
{
    // function to check Neon Number
    static bool checkNeon(int x)
    {
        // storing the square of x
        int sq = x * x;
 
        // calculating the sum of digits
        // of sq
        int sum_digits = 0;
        while (sq != 0)
        {
            sum_digits = sum_digits + sq % 10;
            sq = sq / 10;
        }
        return (sum_digits == x);
    }
 
    // Driver Code
    public static void Main()
                         
    {
        // Printing Neon Numbers upto 10000
        for (int i = 1; i <= 10000; i++)
            if (checkNeon(i))
                Console.Write(i + " ");
    }
}
 
// This code is contributed by vt_m.

PHP

<?php
// PHP program to check and print
// Neon Numbers upto 10000
 
function checkNeon($x)
{
     
    // storing the square of x
    $sq = $x * $x;
 
    // calculating the 
    // sum of digits of sq
    $sum_digits = 0;
    while ($sq != 0)
    {
        $sum_digits = $sum_digits +
                         $sq % 10;
        $sq = $sq / 10;
    }
    return ($sum_digits == $x);
}
 
    // Driver Code
    // Printing Neon Numbers
    // upto 10000
    for ($i = 1; $i <= 10000; $i++)
        if (checkNeon($i))
            echo $i . " ";
             
// This code is contributed by Sam007
?>

Javascript

<script>
 
// Javascript program to check and print
// Neon Numbers upto 10000
 
    // function to check Neon Number
    function checkNeon(x)
    {
        // storing the square of x
        let sq = x * x;
 
        // calculating the sum of digits
        // of sq
        let sum_digits = 0;
        while (sq != 0) {
            sum_digits = sum_digits + sq % 10;
            sq = Math.floor(sq / 10);
        }
        return (sum_digits == x);
    }
 
// driver program
 
       // Printing Neon Numbers upto 10000
        for (let i = 1; i <= 10000; i++)
            if (checkNeon(i))
                document.write(i + " ");
         
</script>

Publicación traducida automáticamente

Artículo escrito por GeeksforGeeks-1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *