Count Smaller Numbers Whose XOR with N Produces Greater Value in C++

Sunidhi Bansal
Updated on 31-Aug-2020 11:30:51

131 Views

We are given an integer number let’s say, num and the task is to count the smaller numbers less than num whose XOR with num will result in a value greater than the XOR value..The truth table for XOR operation is given belowABA XOR B000101011110Input − int num = 11Output − Count of smaller numbers whose XOR with n produces greater value are − 4Explanation −We are given with the num as 11 which means we need to find XOR of num with the numbers less than num. So the numbers are 1 XOR 11 < 11(FALSE), 2 XOR 11 ... Read More

Count of Alphabets with ASCII Value Less Than and Greater Than K in C++

Sunidhi Bansal
Updated on 31-Aug-2020 11:28:41

324 Views

We are given a string of any length and the task is to calculate the count of alphabets having ASCII values less than or greater than or equals to the given integer value k.ASCII value for character A-Z are given belowABCDEFGHIJKLMNOPQRS65666768697071727374757677787980818283TUVWXYZ84858687888990ASCII value for characters a-z are given belowabcdefghijklmnopqrs979899100101102103104105106107108109110111112113114114tuvwxyz116117118119120121122Input − str = “TuTorials PoinT”, int k = 100Output −Count of alphabets having ASCII value less than k are − 6Count of alphabets having ASCII value equals or greater than k are − 9Explanation −We are given with k as 100 so we will check ASCII values of the characters in the ... Read More

Count of Pairs Whose Sum is Divisible by N in C++

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

163 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 a = 2, b = 3, n = 2Output − Count of pairs from 1 to a and 1 to b whose sum is divisible by N are − 3Explanation −Firstly, We will start from 1 to a which includes 1, 2 Now, we will start from 1 to b which includes 1, 2, 3 So the pairs that ... Read More

Count of Pairs (x, y) in an Array such that x < y in C++

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

298 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

435 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

211 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

2K+ 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

227 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 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

Advertisements