Skip to content

Commit

Permalink
Removed infinite loop from Nth magic no.
Browse files Browse the repository at this point in the history
  • Loading branch information
mahis929 committed Oct 9, 2018
1 parent 7087bdf commit fbee54a
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions BitManipulation/Nth_magic_number/nth_magic_number.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
#include <bits/stdc++.h>
using namespace std;

int nthMagicNo(int n)
{
int pow = 1, answer = 0;



while (n)
{
pow = pow*5;

if (n & 1)
answer += pow;

pow = pow*5;


if (n & 1)
answer += pow;


n >>= 1;
}
return answer;
}

int main()
{
int n;
cin>>n;
cin>>n;
cout << "nth magic number is " << nthMagicNo(n) << endl;
return 0;
}
}

0 comments on commit fbee54a

Please sign in to comment.