-
Notifications
You must be signed in to change notification settings - Fork 317
Description
This is my code.........
#include
#include<math.h>
using namespace std;
int main()
{
//binary to decimal ................
int n;
cin>>n;
int ans = 0;
int i = 0;
while( n != 0 )
{
int bits = n&1;
ans = (bits * pow(10, i))+ans;
n = n>>1;
i++;
}
cout<<ans<<endl;
}
but the output is throwing something I don't understand, I guess it is running 32 times as an integer takes 4bytes at first it asks for the Number as per the code but later it asks for the enter button again and again.......
here is the output
PS E:\Data_Structure> cd "e:\Data_Structure\Exercise" ; if (
6
Oops, something went wrong. Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
Last 152 Keys:
c d Space " e : \ D a t a _ S t r u c t u r e \ E x e r c i s e \ " Space ; Space i f Space ( $ ? ) Space { Space g + + Space c o u
n t 1 ' s b i t . c p p Space - o Space c o u n t 1 ' s b i t Space } Space ; Space i f Space ( $ ? ) Space { Space . \ c o u n t 1 ' s b i t Space } Enter
6 Enter
Enter
6 Backspace Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Enter
Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -1.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
at Microsoft.PowerShell.PSConsoleReadLine.AcceptLineImpl(Boolean validate)
at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction,
Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
Note:- Same code is running in online compiler................ for example...programiz