fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <fstream>
  4. #include <cmath>
  5. #include <array>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int num, remainder_count;
  11. do
  12. {
  13. std::array<int, 15> remainder= {{0}};
  14. remainder_count = 15;
  15.  
  16. num = 50;
  17. if (num > 0 && num <= 65535)
  18. {
  19. while (num > 0)
  20. {
  21. remainder.at(remainder_count) = num % 2;
  22. num /= 2;
  23. remainder_count--;
  24. }
  25.  
  26. remainder_count = 0;
  27. while (remainder_count < 16)
  28. {
  29. if (remainder_count % 4 == 0)
  30. {
  31. cout << " ";
  32. }
  33. cout << remainder[remainder_count];
  34. remainder_count++;
  35. }
  36. }
  37. else if (num == 0)
  38. cout << "0000 0000 0000 0000" << endl;
  39.  
  40. else
  41. cout << "Error! Invalid Input." << endl;
  42. } while (false);
  43. }
Runtime error #stdin #stdout #stderr 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::out_of_range'
  what():  array::at: __n (which is 15) >= _Nm (which is 15)