Last active
January 17, 2019 17:39
-
-
Save haixinsong/bc99d649a95a14c0231a679a9aef4840 to your computer and use it in GitHub Desktop.
decimal number display as binary number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() | |
| { | |
| int input_number, temp_number, display_number = 0, ten_power = 1; | |
| cout << "please input a positive integer:" << endl; | |
| cin >> input_number; | |
| temp_number = input_number; | |
| while (temp_number > 0) | |
| { | |
| display_number = display_number + temp_number % 2 * ten_power; | |
| temp_number = temp_number / 2; | |
| ten_power = ten_power * 10; | |
| } | |
| cout << "the decimal number " << input_number << " display as binary number is: " << display_number << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment