Write a short C++ function, isTwoPower, that takes an int i and returns true if and only if i is a power of 2. Do not use multiplication or division,
`Hey,
Note: If you have any queries related to the answer please do comment. I would be very happy to resolve all your queries.
#include<iostream>
using namespace std;
bool isTwoPower(int i)
{
// use of bitwise AND (&) operator
if((i&(i-1))==0)
return
true;
else
return
false;
}
int main()
{
// declaring the array n
int i;
cout<<"Enter integer: ";
cin>>i;
if(isTwoPower(i))
cout<<"True";
else
cout<<"False";
return 0;
}
Kindly revert for any queries
Thanks.
Write a short C++ function, isTwoPower, that takes an int i and returns true if and...
Write a function that takes an int as an argument and returns true if the int is an even number and false if not. In any case change the value of the original argument to twice its value. Use the integers 0 through 4 as test cases. Do not use any arrays.
Write a C function that takes a long int y as argument as well as two integers n and m, the function should swap byte i and j of a long int y (64-Bit Integer).and returns a long int. long int swapBytes(long int y, int i, int j) Rules: Not allowed to use division, multiplication, or modulus, relative comparison (<, >, <=, >=), loops, switches, function calls, macros, conditionals (if or ?:) ALLOWED to use all bit level and logic...
Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...
/* Write a function that takes as an argument the value x, and returns the result of the expression: 20x^4 - 12x^3 - 3x^2 + 15x + 3 Note: No importing; use the power function given to you, and use it as a reference for writing functions (note also that main itself if a function!). */ public class Exercise9_1 { public static void main(String[] args) { int num = 5, pow = 2; System.out.println(num...
*Please write in code in C* First, write a function called prime_check(int x) that takes an integer number as an input then return 1 if it is a prime number nd returns 0 if it is a composite number Then, Write a program that prompt the user to input two numbers: Print the multiplication of these two numbers if both of them are prime. Or Print " Sorry at least one of your number is composite" if otherwise
In C++, write a function isOdd() that takes one integer parameter. The function returns true if the number if odd and false otherwise.
C ++Write a function, anyThree (int a[], int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or equal to 0. Write a function, anyThree (int all, int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or...
PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...
Write a function that takes a list as an argument and returns true if the list is already sorted in increasing order. (You should not sort the list, and make sure that you just iterate over the list once! Only one loop!) WRITE THE CODE IN PYTHON
write a c++ function, do not #include anything, that returns the max of 6 ints int max(int, int, int, int, int, int); allowed to use built in max(int, int) function.