#include "stdafx.h" #include <iostream> using namespace std; int binary(int x) { int arr[99], mod, quo, i = 1, ctr = 0, sum = 0; do { mod = x % 2; arr[ctr] = mod; quo = x / 2; x = quo; arr[ctr] *= i; sum += arr[ctr]; ctr++; i *= 10; } while (x != 0); return sum; } int main() { int arr[256], index = 0; for (int i = 1; i <= 256; i++) { arr[index] = binary(i); index++; } for (index = 0; index < 256; index++) { // output cout << index+1 << ": " << arr[index] << endl; } cin.get(); return 0; }
Output