Programming Articles - Page 1027 of 3363

C++ program to find greatest among four input integers

Arnab Chakraborty
Updated on 07-Oct-2021 07:27:19

6K+ Views

Suppose we have four integers a, b, c and d. We shall have to find the greatest number among them by making our own function. So we shall create one max() function that takes two numbers as input and finds the maximum, then using them we shall find maximum of all four numbers.So, if the input is like a = 75, b = 18, c = 25, d = 98, then the output will be 98.To solve this, we will follow these steps −define a function max(), this will take x and yreturn maximum of x and ytake four numbers ... Read More

Program to distribute repeating integers in Python

Arnab Chakraborty
Updated on 07-Oct-2021 07:52:26

218 Views

Suppose we have an array nums, there are at most 50 unique values. We also have another array called quantity, where quantity[i] denotes the amount of values the ith customer ordered.We have to check whether it is possible to distribute nums such thatThe ith customer gets exactly quantity[i] items, The value that the ith customer gets are all equal, andAll customers are satisfied.So, if the input is like nums = [5, 1, 2, 2, 3, 4, 4, 3, 3] quantity = [2, 2, 3], then the output will be True because two customer wants two elements each, so they can ... Read More

C++ program to convert all digits from the given range into words

Arnab Chakraborty
Updated on 07-Oct-2021 07:24:41

452 Views

Suppose we have two digits a and b. We shall have to convert each digit into words and print them one by one. Printing digits into words means for a digit 5, it should print "Five".So, if the input is like a = 2, b = 6, then the output will beTwo Three Four Five SixTo solve this, we will follow these steps −if d < 0 and d > 9, then:return ("Beyond range of 0 - 9")otherwise when d is same as 0, then:return ("Zero")otherwise when d is same as 1, then:return ("One")otherwise when d is same as 2, ... Read More

Program to find minimum one bit operations to make integers zero in Python

Arnab Chakraborty
Updated on 07-Oct-2021 07:20:00

358 Views

Suppose we have a number n, we have to transform it into 0 using the following operations any number of times −Select the rightmost bit in the binary representation of n.Change the ith bit in the binary representation of n when the (i-1)th bit is set to 1 and the (i-2)th through 0th bits are set to 0.So finally we have to find the minimum number of operations required to transform n into 0.So, if the input is like n = 6, then the output will be 4 because initially 6 = "110", then convert it to "010" by second ... Read More

C++ program to convert digits to words using conditional statements

Arnab Chakraborty
Updated on 07-Oct-2021 07:20:49

1K+ Views

Suppose we have a digit d, we shall have to convert it into words. So if d = 9, our output should be "Nine". If we provide some d which is beyond the range of 0 and 9, it will return appropriate output.So, if the input is like d = 3, then the output will be "Three".To solve this, we will follow these steps −Define a function solve(), this will take d, if d < 0 and d > 9, then:return ("Beyond range of 0 - 9")otherwise when d is same as 0, then:return ("Zero")otherwise when d is same as ... Read More

Program to find out how many transfer requests can be satisfied in Python

Arnab Chakraborty
Updated on 07-Oct-2021 07:13:27

123 Views

Suppose, there are n number of hostel rooms numbered from 0 to n-1. The students in the hostel rooms want to transfer to another room, and they place several requests to do that. No hostel seat remains vacant, a transfer request is only taken care of if another student takes the place of the student willing to transfer. So, given the requests, we have to find out how many requests can be satisfied.So, if the input is like n = 3, requests = [[0, 2], [1, 0], [2, 1]], then the output will be 3.The student in room 0 transfers ... Read More

C++ program to take integer and float as input and return their sum

Arnab Chakraborty
Updated on 07-Oct-2021 07:07:54

3K+ Views

Suppose we have two numbers a and b, a is integer and b is a float. We shall have to take them from standard input and display the sum.So, if the input is like a = 10 b = 56.23, then the output will be Sum: 66.23To solve this, we will follow these steps −To display output into the standard output device we can use extraction operator ()ExampleLet us see the following implementation to get better understanding −#include using namespace std; int main(){    int a;    float b;    cout a >> b;    cout

Program to find out the shortest path to reach the goal in Python

Arnab Chakraborty
Updated on 06-Oct-2021 13:53:47

443 Views

Suppose, we are given a grid where the cells contain various symbols such as 'X', 'O', '*' and '#' and the symbols have various meanings.'#' is the goal cell that we want to reach.'O' is a free cell via which we can travel to the goal cell.'*' is our position in the cell.'X' is a blocked cell, via which we cannot travel.We have to find out the number of moves required to reach the goal cell from our current position in the grid. If the goal is not reachable, we return -1. The grid is given as input to the ... Read More

Program to find largest submatrix with rearrangements in Python

Arnab Chakraborty
Updated on 06-Oct-2021 13:39:57

341 Views

Suppose we have an m x n binary matrix, we can rearrange the columns of the matrix in any order. We have to find the area of the largest submatrix within matrix where every element of the submatrix is 1 after performing some reordering task.So, if the input is like101111001then the output will be 4 because, after column swapping we are getting matrix like110111010here maximum submatrix is of square sized with four 1's.To solve this, we will follow these steps −row := number of rows of matrix, col := number of columns of matrixfor j in range 0 to col ... Read More

Program to find tuple with same product in Python

Arnab Chakraborty
Updated on 06-Oct-2021 13:27:38

529 Views

Suppose we have an array nums with unique positive values, we have to find the number of tuples (a, b, c, d) such that a*b = c*d where a, b, c, and d are elements of nums, and all elements a, b, c and d are distinct.So, if the input is like nums = [2, 3, 4, 6], then the output will be 8 because we can get tuples like (2, 6, 3, 4), (2, 6, 4, 3), (6, 2, 3, 4), (6, 2, 4, 3), (3, 4, 2, 6), (4, 3, 2, 6), (3, 4, 6, 2), (4, 3, ... Read More

Advertisements