Skip to content

Instantly share code, notes, and snippets.

@JellyWX
Created February 6, 2019 09:15
Show Gist options
  • Save JellyWX/37301676b52a40dd55d5064b1ae680cd to your computer and use it in GitHub Desktop.
Save JellyWX/37301676b52a40dd55d5064b1ae680cd to your computer and use it in GitHub Desktop.
#include <iostream>
int main() {
while (true) {
std::cout << "Type 2 numbers: ";
long num1, num2;
std::cin >> num1 >> num2;
long out = 0;
while (num2 != 1) {
std::cout << "\t" << num2 << std::endl;
std::cout << "\t" << num1 << std::endl;
if (num2 % 2 == 1) {
std::cout << "Add extra" << std::endl;
out += num1;
}
num1 = num1 << 1;
num2 = num2 >> 1;
}
out += num1;
std::cout << out << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment