#include <iostream> #include <conio.h> using namespace std; int main() { int n, i = 0, x; int a[i]; cin >> n; while (n > 0) { i++; a[i] = n % 2; n = n / 2; } int l = i; x = a[4]; for (i; i >= 1; i--) { cout << a[i]; } cout << endl; for (i; i >= 2; i--) { a[i] = a[i - 1]; } a[1] = x; for (i; l >= 1; i--) { cout << a[i]; } _getch(); return 0; } 

For some reason, the first element does not want to stand in the place of the last.

Closed due to the fact that off-topic by user194374, VenZell , aleksandr barakin , D-side , Kromster July 18 '16 at 11:17 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Community spirit, VenZell, aleksandr barakin, D-side, Kromster
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Let's start with the fact that you have uncertain behavior. i = 0; int a [i]; total your array of zero length. it doesn't make sense to look at the code further because anything can happen when stack damage occurs - Mike
  • one
    for (i; l >= 1; i--) { .. } - with l >= 1 this is an infinite loop, for example. - Regent
  • Well, how can I make an array with a long i? - goodalien
  • one
    @ goodalien1125 use std :: vector or new int [i]. - αλεχολυτ
  • 2
    @ goodalien1125 alexout offered you a couple of options. You can also create an array with a fixed, obviously larger than the desired length. but this is from the "Bad Advice" series. - Regent

0