Found 7197 Articles for C++

Count pairs with Bitwise XOR as ODD number in C++

Sunidhi Bansal
Updated on 31-Aug-2020 09:41:31

228 Views

We are given an integer array and the task is to count the total number of pairs that can be formed using the given array values such that the XOR operation on the pairs will result in an ODD value.The truth table for XOR operation is given belowABA XOR B000101011110Input − int arr[] = {2, 8, 1, 5, 11}Output − Count of pairs with Bitwise XOR as ODD number are − 6ExplanationExplanation −a1a2a1 XOR a228102132572119819851381131541111051114Approach used in the below program is as followsInput an array of integer elements to form an pairCalculate the size of an array pass the data ... Read More

Count pairs with Bitwise XOR as EVEN number in C++

Sunidhi Bansal
Updated on 31-Aug-2020 09:39:18

223 Views

We are given an integer array and the task is to count the total number of pairs that can be formed using the given array values such that the XOR operation on the pairs will result in an EVEN value.The truth table for XOR operation is given belowABA XOR B000101011110Input − int arr[] = {2, 8, 1, 5, 11}Output − Count of pairs with Bitwise XOR as EVEN number are − 4Explanation −a1a2a1 XOR a228102132572119819851381131541111051114Approach used in the below program is as followsInput an array of integer elements to form an pairCalculate the size of an array pass the data ... Read More

Count pairs with bitwise OR less than Max in C++

Sunidhi Bansal
Updated on 31-Aug-2020 14:09:30

156 Views

We are given an integer array and the task is to count the total number of pairs that can be formed using the given array values such that the OR operation on the pairs will result in the value less than MAX value in the given pair.The truth table for OR operation is given belowABAVB000101011111Input − int arr[] = {2, 5, 1, 8, 9}Output − Count of pairs with bitwise OR less than Max are − 3Explanation −XYX V Y257>5=FALSE213>2=FALSE2810>8=FALSE2911>9=FALSE515=5 TRUE5813>8=FALSE5913>9=FALSE189>8=FALSE1910>9=FALSE899=9= TRUEApproach used in the below program is as followsInput an array of integer elements to form an pairCalculate the ... Read More

Count pairs with Bitwise OR as Even number in C++

Sunidhi Bansal
Updated on 31-Aug-2020 09:19:14

171 Views

We are given an integer array and the task is to count the total number of pairs that can be formed using the given array values such that the OR operation on the pairs will result in an even number.The truth table for OR operation is given belowABAVB000101011111Input − int arr[] = {2, 5, 1, 8, 9}Output − Count of pairs with Bitwise OR as EVEN number are − 2Explanation −a1a2a1Va225721328102911515581359131891910899Approach used in the below program is as followsInput an array of integer elements to form an pairCalculate the size of an array pass the data to the function for ... Read More

Count pairs with Bitwise-AND as even number in C++

Sunidhi Bansal
Updated on 31-Aug-2020 09:15:58

173 Views

We are given an integer array and the task is to count the total number of pairs that can be formed using the given array values such that the AND operation on the pairs will result in an even number.The truth table for AND operation is given belowABA^B000100010111Input − int arr[] = {2, 5, 1, 8, 9}Output − Count of pairs with Bitwise AND as EVEN number are − 7Explanation −a1a2a1^a2250210280290511580591180191898Approach used in the below program is as followsInput an array of integer elements to form an pairCalculate the size of an array pass the data to the function for ... Read More

Count pairs with Bitwise AND as ODD number in C++

Sunidhi Bansal
Updated on 31-Aug-2020 09:12:59

159 Views

We are given an integer array and the task is to count the total number of pairs that can be formed using the given array values such that the AND operation on the pairs will result in an odd number.The truth table for AND operation is given belowABA^B000100010111Input − int arr[] = {2, 5, 1, 8, 9}Output − Count of pairs with Bitwise AND as ODD number are − 3Explanation −a1a2a1^a2250210280290511580591180191898Approach used in the below program is as followsInput an array of integer elements to form an pairCalculate the size of an array pass the data to the function for ... Read More

Count of parallelograms in a plane in C++

Sunidhi Bansal
Updated on 31-Aug-2020 09:08:00

186 Views

We are given a plane containing points forming the parallelogram and the task is to calculate the count of parallelograms that can be formed using the given points. In parallelograms opposite sides of a quadrilateral are parallel and therefore opposite angles are equal.Input −int a[] = {0, 2, 5, 5, 2, 5, 2, 5, 2} Int b[] = {0, 0, 1, 4, 3, 8, 7, 11, 10}Output − Count of parallelograms in a plane − 3Explanation − we are given with the (x, y) points and using these points we can form a count of 3 parallelograms as shown in ... Read More

Count set bits in a range in C++

Sunidhi Bansal
Updated on 31-Aug-2020 09:03:11

357 Views

We are given an integer number let’s say, num and the range with left and right values. The task is to firstly calculate the binary digit of a number and then set the loop from the left digit till the right digit and then in the given range calculate the set bits.Set bits in a binary number is represented by 1. Whenever we calculate the binary number of an integer value then it is formed as the combination of 0’s and 1’s. So, the digit 1 is known as set bit in the terms of the computer.Input − int number ... Read More

Count set bits in an integer in C++

Sunidhi Bansal
Updated on 11-Dec-2024 09:52:15

5K+ Views

We are given an integer number let’s say, num and the task is to first calculate the binary digit of a number and then calculate the total set bits of a number. Set bits in a binary number are represented by 1. Whenever we calculate the binary number of an integer value then it is formed as the combination of 0’s and 1’s. So, the digit 1 is known as a set bit in terms of the computer. Example 1 Input − int number = 50 Output − The count ... Read More

Count total bits in a number in C++

Sunidhi Bansal
Updated on 31-Aug-2020 08:58:20

5K+ Views

We are given an integer number let’s say, num and the task is to firstly calculate the binary digit of a number and calculate the total digits of a number.Input − int number = 50Output − Count of total bits in a number are − 6Explanation − Binary representation of a number 50 is 110010 and if we calculate it in 8-digit number then two 0’s will be appended in the beginning. So, the total bits in a number are 6.Input − int number = 10Output − Count of total bits in a number are − 6Explanation − Binary representation ... Read More

Advertisements