Found 7347 Articles for C++

Count of pairs (x, y) in an array such that x < y in C++

Sunidhi Bansal
Updated on 31-Aug-2020 11:22:15

212 Views

We are given an integer array and the task is to count the total number of pairs (x, y) that can be formed using the given array values such that the integer value of x is less than y.Input − int arr[] = { 2, 4, 3, 1 }Output − Count of pairs (x, y) in an array such that x < y are − 6Explanation −XYX < Y24true23true21false43false41false42false32false12true34true14true31false13falseApproach 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 further processingCreate ... Read More

Count Odd and Even numbers in a range from L to R in C++

Sunidhi Bansal
Updated on 31-Aug-2020 11:19:56

332 Views

We are given a range starting from L to R of integer values and the task is to calculate the count of odd numbers and the even numbers in the range.Input − L = 7, R = 17Output − Count of Even numbers in a range from L to R are − 5Count of Odd numbers in a range from L to R are − 6Input − L = 1, R = 10Output − Count of Even numbers in a range from L to R are − 5Count of Odd numbers in a range from L to R are − ... Read More

Count pairs with Odd XOR in C++

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

138 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 Odd XOR are − 6Explanation −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 to the function ... Read More

Count pairs with given sum in C++

Sunidhi Bansal
Updated on 31-Aug-2020 09:45:01

1K+ 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 sum of the pairs is equal to the given sum.Input − int arr[] = {2, 8, 1, 5, 11}, sum = 10Output − Count of pairs with given sum 13 is − 2Explanation −a1a2a1 + a22810213257211138198513811191561111251116Input − int arr[] = {2, 8, -1, 5, -11}, sum = 6Output − Count of pairs with given sum 6 is − 1Explanation −a1a2a1 + a228102-112572-11-98-1785138-11-31561-11-105-11-6Approach used in the below program is as followsInput an ... Read More

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

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

146 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

141 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

101 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

98 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

106 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

90 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

Advertisements