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
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
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
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
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
We are given a string containing Uppercase letters, Lowercase letters, specials characters and number values also. The task is to calculate the frequency of all types of characters, special characters and numeric values in the string.Uppercase Letters − A - Z having ASCII values from 65 - 90 where, 65 and 90 are inclusive.Lowercase Letter − a - z having ASCII values from 97 - 122 where, 97 and 122 are inclusive.Numeric values − 0 - 9 having ASCII values from 48 - 57 where, 48 and 57 are inclusive.Special Characters − !, @, #, $, %, ^, &, *Input ... Read More
We are given with a sentence or string containing words that can contain spaces, new line characters and tab characters in between. The task is to calculate the total number of words in a string and print the result.Input − string str = “welcome to tutorials point\t”Output − Count of words in a string are − 4Explanation − There are four words in a string i.e. welcome, to, tutorials, point and the rest are spaces(“ ”), next line character() and tab character(\t) present between the words.Input − string str = “honesty\t is the best policy”Output − Count of words in ... Read More
We are given an array of integer elements which contains duplicate values and the task is to calculate the frequencies of the distinct elements present in an array and print the result.Input − int arr[] = {1, 1, 2, 3, 4, 1, 2, 3}Output −frequency of 1 is: 3 frequency of 2 is: 2 frequency of 3 is: 2 Frequency of 4 is: 1Input − int arr[] = {2, 3, 4, 1, 5}Output −frequency of 1 is: 1 frequency of 2 is: 1 frequency of 3 is: 1 Frequency of 4 is: 1 Frequency of 5 is: 1Approach used in ... Read More
We are given two numbers L and R that define a range [L, R]. The goal is to find all numbers between L and R that are even, and sum of whose digits is divisible by 3.We will do this by calculating the sum of digits of all even numbers between L and R and increment count if that sum%3==0.Let us understand with examples.Input − L=10, R=20Output − Count of all even numbers in the range [L, R] whose sum of digits is divisible by 3: 2Explanation − Numbers between 10 and 20 that are even. 10, 12, 14, 16, ... Read More
We are given a string of numbers 0 to 9. The string represents a decimal number. The goal is to find all substrings that represent a decimal number which is greater than number X. Condition is that substring should not start with 0. I.e in “2021”, “02”, “021”. “0” will not be included.We will do this by checking the first value of all substrings, if it is greater than 0 then start making substrings from that index by converting them into integers using stoi(). If substring>X increment count.Let us understand with examples.Input − str=”123” X=12Output − Count of number of ... Read More