Found 33676 Articles for Programming

Program to find the maximum element in a Matrix in C++

Ayush Gupta
Updated on 15-Sep-2020 15:14:05

1K+ Views

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

Maximum of four numbers without using conditional or bitwise operator in C++

Ayush Gupta
Updated on 15-Sep-2020 15:15:42

645 Views

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

Stamping The Sequence in C++

Arnab Chakraborty
Updated on 08-Jun-2020 10:43:06

292 Views

Suppose we want to make a target string of lowercase letters.At first, we have the sequence as n '?' marks (n is the length of target string). We also have a stamp of lowercase letters.On each turn, we can place the stamp over the sequence, and replace every letter in the with the corresponding letter from that stamp. You can make up to 10 * n turns. As an example consider the initial sequence is "?????", and the stamp is "abc", then we may make strings like "abc??", "?abc?", "??abc" in the first turn.If the sequence is possible to stamp, ... Read More

Program to find the Largest Number using Ternary Operator in C++

Ayush Gupta
Updated on 15-Sep-2020 15:17:13

2K+ Views

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

Program to find the largest and smallest ASCII valued characters in a string in C++

Ayush Gupta
Updated on 15-Sep-2020 15:18:18

2K+ Views

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

Program to find the kth character after decrypting a string in C++

Ayush Gupta
Updated on 08-Jun-2020 10:37:35

226 Views

In this tutorial, we will be discussing a program to find the kth character after decrypting a string.For this, we will be provided with a string that will consist of characters and numbers and integer K. Our task is to decrypt the given string and find the character at Kth position.Example Live Demo#include #include using namespace std; //finding decrypted Kth character char findKthChar(string s, int k) {    int len = s.length();    int i = 0;    int total_len = 0;    while (i < len) {       if (isalpha(s[i])) {          total_len++; ... Read More

Shortest Path to Get All Keys in C++

Arnab Chakraborty
Updated on 08-Jun-2020 10:40:00

579 Views

Suppose we have a grid. There are few symbols. "." is indicating empty cell, "#" is for wall, "@" is for starting point, ("a", "b", ...) all are keys, and ("A", "B", ...) all are locks. We will start from the starting point, and one move consists of walking one space in one of the 4 directions (left, right, top, bottom). We will not go outside the grid, and there are walls to block our way. If we walk over a key, we pick it up. We can't walk over a lock unless we have the corresponding key.For each lock ... Read More

Program to find the initials of a name in C++

Ayush Gupta
Updated on 15-Sep-2020 15:19:16

1K+ Views

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

Program to find the Interior and Exterior Angle of a Regular Polygon in C++

Ayush Gupta
Updated on 15-Sep-2020 15:20:08

484 Views

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

Program to find the Hidden Number in C++

Ayush Gupta
Updated on 15-Sep-2020 15:21:21

408 Views

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

Advertisements