Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <cmath>
- using namespace std;
- int main() {
- ofstream myFile;
- myFile.open("binary.doc");
- int bits = 1;
- cout << "Enter number of bits as an integer greater than 0: ";
- cin >> bits;
- int maxPow = pow(2,bits);
- for (int i = 0; i < maxPow; i++) {
- int currPow = maxPow;
- while (currPow != 1) {
- (i % currPow < currPow/2) ? myFile << "0" : myFile << "1";
- currPow /= 2;
- }
- myFile << endl;
- }
- cout << "Printed binary numbers 0-" << maxPow-1 << " to binary.doc\n\n";
- myFile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement