diff --git a/C-Plus-Plus/README.md b/C-Plus-Plus/README.md index 1a933a3695..71eea17c6a 100644 --- a/C-Plus-Plus/README.md +++ b/C-Plus-Plus/README.md @@ -223,6 +223,7 @@ _add list here_ - [Binomial Coefficient (under modulo)](math/binomial_coefficient_under_modulo.cpp) - [Magic Number](math/magic_number.cpp) - [Converting decimal number to binary](math/Convert_decimal_to_binary.cpp) +- [Neon Number](math/neon_number.cpp) - [Krishnamurthy Number](math/krishnamurthy_number.cpp) - [Tower Of Hanoi](math/Tower_Of_Hanoi.cpp) - [Happy Number](math/Happy_Number.cpp) diff --git a/C-Plus-Plus/math/neon_number.cpp b/C-Plus-Plus/math/neon_number.cpp new file mode 100644 index 0000000000..d0606b925f --- /dev/null +++ b/C-Plus-Plus/math/neon_number.cpp @@ -0,0 +1,51 @@ +/* + A neon number is a number where :- + the sum of digits of square of the number is equal to the number. + The task is to check and print neon numbers in a range given by the user. +*/ + +#include +using namespace std; +//Function that prints the sum of digits of a number +int sum_of_digits(int y) +{ + int s = 0,v; + while (y != 0) + { + v=y%10; + s = s + v; + y = y / 10; + } + return s; +} +bool Neon(int n) +{ + int sq = pow(n,2); + int result = sum_of_digits(sq); + //If sum of digits become equal to the number + if (result == n) + return true; + else + return false; +} + +int main() +{ + cout << "Enter the range:"; + int a, b; + cin >> a >> b; + + // Printing Neon Numbers according to the range + cout<<"Neon numbers in between "<