Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 299 of 377

C++ program to demonstrate exception handling

Arnab Chakraborty
Arnab Chakraborty
Updated on 12-Oct-2021 435 Views

Suppose there is a function that calculates some serious complex mathematical operations. But during the operations, some exceptions can occur. We have to handle the different types of exceptions that can occur and perform the following.If the computer is unable to allocate the memory for computation, we have to print 'Memory Low!'If any other C++-related exception occurs, we have to print 'Exception:' then the exception.If something else happens, we print 'Unhandled exception'.We are given an array that contains a pair of values, and we pass it to the function. If any exception occurs, we handle it, or otherwise, we print ...

Read More

C++ program to search specific values in an array

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 4K+ Views

Suppose we are given an array 'arr' that contains n number of sorted integer values. We are also given an array 'query' of size q, and we have to tell either the values in ‘query’ are present in the given array 'arr' or not. If a value in query is present in arr, we print "Present" along with the position where the value is situated in. Otherwise, we print "Not present" and print the position in arr, where the minimum value greater than the value in query is located. We have to remember that the arrays are 1-indexed.So, if the ...

Read More

C++ program to print values in a specified format

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 1K+ Views

Suppose we are given three double values. We have to format them and print them in the following format.We have to print the integer part of the first value in hexadecimal format with lowercase letters.We have to print the second value up to two decimal places, putting a sign before it to show whether it is positive or negative. The second value to be printed has to be rightjustified and 15 characters long, padded with underscores in the left unused positions.We have to print the third value up to nine decimal places in a scientific notation.So, if the input is ...

Read More

Python program to find how much money will be earned by selling shoes

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 464 Views

Suppose in a shoe shop there are n different shoe with different sizes present in an array called size and another list of pairs for m customers called demand is given, where demand[i] contains (shoe_size, money) so a customer with demand i has a demand of shoe whose size is shoe_size and he/she can pay given amount of money. We have to find how much money the shopkeeper can earn by selling these shoes.So, if the input is like shoes = [2, 3, 4, 5, 6, 8, 7, 6, 5, 18] demand = [(6, 55), (6, 45), (6, 55), (4, ...

Read More

Python program to find Cartesian product of two lists

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 6K+ Views

Suppose we have two list of data l1 and l2. We have to find Cartesian product of these two lists. As we know if two lists are like (a, b) and (c, d) then the Cartesian product will be {(a, c), (a, d), (b, c), (b, d)}. To do this we shall use itertools library and use the product() function present in this library. The returned value of this function is an iterator. We have to convert it into list by passing the output into list() constructor.So, if the input is like l1 = [1, 5, 6] l2 = [1, ...

Read More

Python program to print rangoli pattern using alphabets

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 5K+ Views

Suppose we have a number n. We have to create alphabet rangoli of n x n size. n must be within 1 and 26 and it will start from a and end at z when n is 26.So, if the input is like 5, then the output will be--------e-------- ------e-d-e------ ----e-d-c-d-e---- --e-d-c-b-c-d-e-- e-d-c-b-a-b-c-d-e --e-d-c-b-c-d-e-- ----e-d-c-d-e---- ------e-d-e------ --------e--------To solve this, we will follow these steps −for i in range n-1 to 0, decrease by 1, dofor j in range 0 to i-1, doprint "--"for j in range n-1 to i+1, decrease by 1, doprint character whose ASCII is j+97 and print ...

Read More

C++ program to print values of different data types provided as input

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 2K+ Views

Suppose we are given an integer value, a long value, a character value, a float value, and a double value as inputs. We have to print the values that are given to us as input maintaining their precision.So, if the input is like integer value = 15, long value = 59523256297252, character value = 'y', float value = 367.124, double value = 6464292.312621, then the output will be15 59523256297252 y 367.124 6464292.31262To solve this, we will follow these steps −Print the values given as input in separate lines.ExampleLet us see the following implementation to get better understanding −#include #include ...

Read More

C program to demonstrate usage of variable-length arrays

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 380 Views

Suppose we are in charge of building a library system that monitors and queries various operations at the library. We are now asked to implement three different commands that perform the following −By using command 1, we can record the insertion of a book with y pages at shelf x.By using command 2, we can print the page number of the y-th book at shelf x.By using command 3, we can print the number of books on shelf x.The commands are given to us as a 2D array in this format {command type, x, y}. If there is no y ...

Read More

C program to find out the maximum value of AND, OR, and XOR operations that are less than a given value

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 2K+ Views

Suppose we are given two integers k and n. Our task is to perform three operations; bitwise AND, bitwise OR, and bitwise XOR between all pairs of numbers up to range n. We return the maximum value of all three operations between any two pairs of numbers that is less than the given value k.So, if the input is like n = 5, k = 5, then the output will be 4 3 4.The greatest value of AND, OR, and XOR operations between all pairs of numbers that are less than 5 are 4, 3, and 4 respectively. We can ...

Read More

Python Program to calculate function from indicator random variable from given condition

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Oct-2021 355 Views

Suppose we have two values k and n. Consider a random permutation say p1, p2, ..., pn of first n natural numbers numbers 1, 2, ..., n and calculate the value F, such that F = (X2+...+Xn-1)k, where Xi is an indicator random variable, which is 1 when one of the following two conditions holds: pi-1 < pi > pi+1 or pi-1 > pi < pi+1 and Xi is 0 otherwise. We have to find the expected value of F.So, if the input is like k = 1 n = 1000, then the output will be 1996/3To solve this, we ...

Read More
Showing 2981–2990 of 3,768 articles
« Prev 1 297 298 299 300 301 377 Next »
Advertisements