Skip to content

Commit

Permalink
Neon number added (HarshCasper#3050)
Browse files Browse the repository at this point in the history
* Neon number added

* Update neon_number.cpp

* Update neon_number.cpp

* Update neon_number.cpp

* Update neon_number.cpp

* Update neon_number.cpp

* Update neon_number.cpp

* Update neon_number.cpp

* Update neon_number.cpp

* Update neon_number.cpp

Co-authored-by: ankan1811 <[email protected]>
  • Loading branch information
ankan1811 and ankan1811 authored Mar 16, 2021
1 parent c594d07 commit 1d0447c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions C-Plus-Plus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 51 additions & 0 deletions C-Plus-Plus/math/neon_number.cpp
Original file line number Diff line number Diff line change
@@ -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 <bits/stdc++.h>
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 "<<a<<" to "<<b<<" are : ";
for (int i = a; i <= b; i++)
if (Neon(i) == true)
cout << i << " ";
}
/*
Input: Enter the range:1 10000
Output: Neon numbers in between 1 to 10000 are : 1 9
*/
/*
Time Complexity:O(nlogn) //where n is the range of a to b.
Space Complexity:O(1)
*/

0 comments on commit 1d0447c

Please sign in to comment.