123456789101112131415161718192021222324
#include <iostream> #include <stdlib.h> using namespace std; int main() { int number, temp, a[4]; cout << "Enter the number less than 16"; cin >> number; if (number < 0 || number > 15) { cout << "Please enter valid number"; exit; } for (int i = 3; i >= 0; --i) { temp = number / 2; int tmp = number % 2; a[i] = tmp; number = temp; } for (int j = 0; j < 4; ++j) { cout << a[j]; } return 0; }