Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- #include <algorithm>
- std::string calc(int number)
- {
- std::string tempstring;
- int temp = number;
- while(temp)
- {
- if(temp%2)
- tempstring.append("1");
- else
- tempstring.append("0");
- temp = temp/2;
- }
- std::reverse(tempstring.begin(),tempstring.end());
- return tempstring;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- while(1)
- {
- int number = 0;
- std::cout << "Enter a Number\n";
- std::cin >> number;
- std::cout << calc(number) << "\n";
- }
- }
Add Comment
Please, Sign In to add comment