Created
July 29, 2017 14:37
-
-
Save odeblic/a86b3d52e94f5fe8d2294e8b2801bd86 to your computer and use it in GitHub Desktop.
To be tested...
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> | |
#include <math.h> | |
/* | |
* Complete the function below. | |
*/ | |
int getIntegerComplement(int n) { | |
if(n <= 0) | |
{ | |
n = 0; | |
} | |
else if(n > 100000) | |
{ | |
n = 100000; | |
} | |
int level = 1 + log(n) / log(2); | |
int mask = (2 ^ level) - 1; | |
return ~n & mask ;// & (0xEFFFFFFF); | |
} | |
int main() | |
{ | |
int number; | |
std::cout << "Please type the number : " << std::endl; | |
std::cin >> number; | |
int level = 1 + log(number) / log(2); | |
int mask = (2 ^ level) - 1; | |
std::cout << "Log : " << level << std::endl; | |
std::cout << "Complement : " << getIntegerComplement(number) << std::endl; | |
std::cout << "Mask : " << mask << std::endl; | |
return 0; | |
int height; | |
std::cout << "Please type the height : " << std::endl; | |
std::cin >> height; | |
if(height < 1) | |
{ | |
height = 1; | |
} | |
else if(height > 100) | |
{ | |
height = 100; | |
} | |
for(int row = 1; row <= height; ++row) | |
{ | |
for(int col = 1; col <= height; ++col) | |
{ | |
if(col < height - row + 1) | |
{ | |
std::cout << " "; | |
} | |
else | |
{ | |
std::cout << "#"; | |
} | |
} | |
std::cout << std::endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment