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
In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the minimum and maximum element of an array in C++.Problem Description − Here, we have an array arr[]. The contains n integer values. We have to find the maximum value and minimum value out of all values of the array.Let’s take an example to understand the problem, Inputarr[] = {2, 1, 6, 9, 4, 10, 15, 21}Outputmax = 21 , min = 1Solution ApproachThere can be multiple solutions to the problem, One solution would be directly comparing elements of ... Read More
In this problem, we are given an array arr[] of integers and a number k. Our task is to create a program to find the Maximum product of subsequence of size k in C++.Problem Description − Here, we need to find the subsequence of size k, 1
In this problem, we are given an undirected connected tree T with n nodes. Our task is to create a program to find the Maximum product of two nonintersecting paths in a tree in C++.Problem Description − To find the maximum product of two nonintersecting paths in a tree. We will find all the non-interesting paths and then find the product of their lengths.Let’s take an example to understand the problem, InputGraph −Output8ExplanationThe non-intersecting paths that are considered are C-A-B and F-E-D-G-H.The lengths are 2 and 4. Product = 8.Solution ApproachThe solution to this problem is by traversing the tree ... Read More