Programming Articles

Page 1473 of 2547

Check if a pair with given product exists in a Matrix in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 184 Views

We have one matrix of order N x M. And a product K. The task is to check whether a pair with the given product is present in the matrix or not.Suppose a matrix is like below −12345678910111213141516Now if the K is 42, then there is a pair like (6, 7)To solve this problem, we will use hashing. We will create hash table by taking all elements of the matrix. We will start traversing the matrix, while traversing, check whether the current element of the matrix is divisible by the given product, and when the product K is divided by ...

Read More

Angle between two Planes in 3D in C++?

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 340 Views

For learning about the angle between two planes in 3D, we need to learn about planes and angles.Plane is a two-dimensional surface that extends to infinity.Angle is the space in degrees between two lines and surfaces which intersect at a point.So, in this problem we need to find the angle between two 3D planes. For this we have two planes that intersect each other and we need to find the angle at which the are intersecting each other.To calculate the angle between two 3D planes, we need to calculate the angle between the normal's of these planes.Here, we have two ...

Read More

C++ program to calculate GST from original and net prices

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 2K+ Views

Given with the original cost and net price as an input and the task is to calculate the GST percentage and display the resultGST stands for Goods and Service task. It is always included in the Net price of the product and before calculating the GST percentage we need to calculate GST amount and for that there are formulas availableNetprice = originalcost + GSTAmountGSTAmount = Netprice – original_costGST_Percentage = (GSTAmount * 100)/ originalcostGST % formula = (GSTAmount*100) / originalcostExampleInput-: cost = 120.00    price = 150.00 Output-: GST amount is = 25.00 % Input-: price = 120.00    cost = ...

Read More

C++ program to calculate Profit Or Loss

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 4K+ Views

Given with the cost price(CP) and the selling price(SP) and the task is to calculate the profit gained or loss incurred.Cost price or CP is the price at which the product is purchased by the seller and the selling price or SP is the price at which the product is sold by the seller.There is a formula to calculate profit gained or loss incurredProfit = Selling price – Cost priceIf Selling price is greater than cost price than there will be a profitLoss = Cost price – Selling priceIf cost price is greater than selling price than there will be ...

Read More

C++ program to Calculate the Edge Cover of a Graph

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 342 Views

Given a n number of vertices of a graph, the task is to calculate the edge cover of the graph. Edge cover is to find the minimum number of edges required to cover every vertex of the graph.Like we have n = 5Then its graph will be like −So its edge cover is 3Let’s take another example where the n is 8And its edge cover will be:4ExampleInput: n= 5 Output: 3 Input: n= 8 Output: 4Approach used below is as follows −Take the input from the userFind the ceiling value of the result of number of vertices by dividing it ...

Read More

C++ program to check if first and the last characters of string are equal

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

Given with an input of string and the task is to check whether the first and last characters of given string is equal or not.ExampleInput-: study Output-: not equal    As the starting character is ‘s’ and the end character of a string is ‘y’ Input-: nitin Output-: yes it have first and last equal characters    As the starting character is ‘n’ and the end character of a string is ‘n’Approach used below is as follows −Input the string and store in an array of strings.Calculate the length of a string using length() functionCheck first and last element of ...

Read More

Minimum Initial Energy Required To Cross Street in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 513 Views

Suppose we have an array where positive and negative numbers are stored. The array is representing the checkpoint from one end to another end of the streets. The positive and negative values are representing the energy at the checkpoints. The positive values can increase energy, and negative number decreases energy. We have to find the initial energy level to cross the street, such that energy level never becomes 0 or less than 0.Suppose we have an array A = {4, -6, 2, 3}. Let the initial energy is 0. So after reaching at first check point, the energy is 4. ...

Read More

Minimum insertions to make a Co-prime array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 265 Views

In this section we will see another interesting problem. Suppose we have an array of N elements. We have to find minimum number of intersection points to make this array as co-prime array. In the co-prime array gcd of every two consecutive elements is 1. We have to print the array also.Suppose we have elements like {5, 10, 20}. This is not co-prime array. Now by inserting 1 between 5, 10 and 10, 20, it will be co-prime array. So the array will be like {5, 1, 10, 1, 20}AlgorithmmakeCoPrime(arr, n): begin    count := 0    for i in ...

Read More

Find any pair with given GCD and LCM in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 378 Views

In this section we will see how to get number of pairs using the given GCD and LCM values. Suppose the GCD and LCM values are 2 and 12. Now the possible pairs of numbers are (2, 12), (4, 6), (6, 4) and (12, 2). So our program will find the count of pairs. That is 4.Let us see the algorithm to understand what will be the technique to solve this problem.AlgorithmcountPairs(gcd, lcm): Begin    if lcm is nit divisible by gcd, then       return 0    temp := lcm/gcd    c := primeFactorCount(temp)    res := shift ...

Read More

The abs(), labs(), llabs() functions in C/C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

What are Integer Functions in C Library?Integer functions are those functions which returns the exact value of an integer. C only supports integer values. In this function the nearest integer which is less than or equal to the argument returns to this function.Types of Integer functions −int = abs (int n); long = labs (long n); long long = llabs (long long n);where n = integer valueWhat is abs(), labs(), llabs() functions ?They are defined as (C Standard General Utilities Library) header file. They give the exact value of integer that is input to them as their argument.abs() function ...

Read More
Showing 14721–14730 of 25,466 articles
Advertisements