In this problem, we are given two points A and B, starting and ending point of a line. Our task is to create a program to find the mid-point of a line in C++.Problem Description − Here, we have a line with starting and ending points A(x1, y1) and B(x2, y2). And we need to find the mid-point of the line.Let’s take an example to understand the problem, Inputa(x1, y1) = (4, -5) b(x2, y2) = (-2, 6)Output(1, 0.5)Explanation(x1 + x2)/2 = 4 - 2 / 2 = 1 (y1 + y2)/2 = -5 + 6 / 2 = 0.5Solution ... Read More
In this problem, we are given two integers that give the head start that is given by A to B and C respectively in a 100-meter race. Our task is to create a program to find the head start in a race in C++.Code Description − Here, there are head starts that are given by A to B and A to C respectively in a 100-meter race. We need to find the relative head start that is given by B to C in the 100-meter race.Let’s take an example to understand the problem, Input20, 28Output90ExplanationA gives B a head-start of ... Read More
In this problem, we are an array arr[] consisting of n integer values. Our task is to create a Program to find the Hidden Number in C++.Code description − For an array, the hidden number, is the number which when subtracted from each element of the array gives the sum 0.Let’s take an example to understand the problem, Inputarr[] = {4, 1, 6, 7, 2}Output4Subtracting 4 from all elements of the array. And adding of values= (1 - 4) + (6 - 4) + (7 - 4) + (4 - 2) = -3 + 2 + 3 - 2 = ... Read More
In this problem, we are given a number n that denotes the sides of a regular polygon. Our task is to create a Program to find the Interior and Exterior Angle of a Regular Polygon in C++.Problem Description − Here, for the given number of sides, we will find the value of each interior and exterior angle of the regular polygon of side n.Interior Angle is the angle between two adjacent sides of a polygon that lies inside the polygon.Exterior Angle is the angle between two adjacent sides of a polygon that lies outside the polygon.Let’s take an example to ... Read More
In the program, we are given a string name that denotes the name of a person. Our task is to create a Program to find the initials of a name in C++.Code Description − Here, we have to find the initials of the name of the person given by the string.Let’s take an example to understand the problem, Inputname = “ram kisan saraswat”OutputR K SExplanationWe will find all the first letters of words of the name.Solution ApproachA simple solution to the problem is by traversing the name string. And all the characters that appear after the newline character or space ... Read More
In this problem, we are given a string. Our task is to create a program to find the largest and smallest ASCII valued characters in a string in C++.Code Description − Here, we have a string that consists of both upperCase and lowerCase characters. And we need to find the characters that have the largest and the smallest ASCII value character.Let’s take an example to understand the problem, Inputstr = “TutroialsPoint”OutputLargest = u smallest = P.ExplanationAccording to ASCII values, upperCase characters are smaller than lowerCase characters.So, the smallest character of upperCase characters (A) has overall the smallest ASCII value. The ... Read More
In this problem, we are given some numbers. Our task is to create a Program to Find the Largest Number using Ternary Operator in C++.The elements can be −Two NumbersThree NumbersFour NumbersCode Description − Here, we are given some numbers (two or three or four). We need to find the maximum element out of these numbers using a ternary operator.Let’s take a few examples to understand the problem, Two NumbersInput − 4, 54Output − 54Three NumbersInput − 14, 40, 26Output − 40Four NumbersInput − 10, 54, 26, 62Output − 62Solution ApproachWe will use ternary Operator, for two, three and four ... Read More
In this problem, we are given four integer numbers. Our task is to create a program to find the maximum of four numbers without using conditional or bitwise operator in C++.Code Description − Here, we have four integer values. And we need to find the maximum value out of these numbers without using any conditional or bitwise operator.Let’s take an example to understand the problem, Inputa = 4, b = 7, c = 1, d = 9Output9Solution ApproachTo solve the problem, we will take two elements first, then take the greater element with pair. For each pair, we will create ... Read More
In this problem, we are given a matrix of size nXm. Our task is to create a program to find the maximum element in a Matrix in C++.Problem Description − Here, we need to simply find the largest element of matrix.Let’s take an example to understand the problem, Inputmat[3][3] = {{4, 1, 6}, {5, 2, 9}, {7, 3, 0}}Output9Solution ApproachThe solution to the problem is by simply traversing the matrix. This is done by using two nested loops, and checking whether each element of the matrix is greater than maxVal. And return the maxVal at the end.Program to illustrate the ... Read More
In this problem, we are given an array arr[] consisting of n integers. Our task is to create a program to find the maximum difference between the index of any two different numbers in C++.Code Description − Here, we need to find the maximum difference between the index of integer values of the array, given that the two integers are different.Let’s take an example to understand the problem, Inputarr[] = {4, 1, 3, 2, 1, 2, 4}Output5ExplanationThe difference between index 0, element 4, and index 5, element 2.Solution ApproachWe will try to find the maximum possible difference between the index ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP