The outputs:
Input a decimal number range from 1 to 31: 16 1 0 0 0 0 Input a decimal number range from 1 to 31: 19 1 0 0 1 1
The codes:
#includeusing namespace std; int main() { cout << "Input a decimal number range from 1 to 31: "; int n; cin >> n; int a[5]; int i =0,j = 0; while (n > 0){ a[j++] = n%2; n = n/2; } for(int i = j; i < 5; ++i){ a[i] = 0; } for(int i =4; i >=0; --i){ cout << a[i] << " "; } return 0; }



