Tag: Cpp

Integer division c++

Integer division problem definition Given the following function which computes integer division. Debug the code and identify the major bugs. Modify the code to fix those bugs. Assume all integer variables are within range and no overflow is about to happen. int Division(int numerator, int denominator) { int quotient = 0; while (numerator > denominator)

Sum of Integers in a Range

Problem Write a function to compute the sum of integers between two given integer values. Solution The naive solution is to loop by going from the lower integer ending at the higher integer while calculating the sum. The other solution is compute the sum using the following formula Sum (1..n) = n (n + 1)/2

Bitwise operators in c++

Problem Write a C++ function that takes a character as input and returns true if the second significant bit of the binary representation of the character is set (i.e equals to 1) otherwise return false. Solution This is a bitwise operations problem. First you need to shift the character one digit to the right then