Found 7197 Articles for C++

C++ code to find out if a name is male or female

Arnab Chakraborty
Updated on 29-Mar-2022 08:47:28

982 Views

Suppose, we are given n strings in an array 'input'. The strings are names, we have to find out if they are male or female names. If a name ends with 'a', 'e', 'i', or 'y'; it can be said that it is a female name. we print 'male' or 'female' for each input in the string.So, if the input is like n = 5, input = {"Lily", "Rajib", "Thomas", "Riley", "Chloe"}, then the output will be Female, Male, Male, Female, Female.StepsTo solve this, we will follow these steps −for initialize i := 0, when i < n, update (increase ... Read More

C++ code to find the number of scans needed to find an object

Arnab Chakraborty
Updated on 29-Mar-2022 08:43:19

195 Views

Suppose, we are given a grid of dimensions m x n. An object is placed at cell (ix, iy) and we have to find the object scanning from a starting position (sx, sy). The scanning algorithm scans the ith row and the j-th column of the grid if it is located at cell (i, j) of the grid. If it has found the object, the scanning stops; if not, the scanning pointer moves to cell in position (i + 1, j + 1) and then scans in the same way. This continues until the item is found. Given the positions, ... Read More

C++ code to find the number of refill packs to be bought

Arnab Chakraborty
Updated on 29-Mar-2022 08:41:38

208 Views

Suppose, there are 'a' number of matches and 'b' number of press conferences to be held in a stadium in a particular week. There are two cafeterias, one in the player dressing room and one in the press conference area. There are two soft drink dispensers in the cafeterias and they need to be filled at the start of the week. The dressing room cafeteria drink dispenser is used heavily, and it needs to be refilled after every 'c' games and the conference area cafeteria's dispenser needs to be refilled after every 'd' events. The stadium maintenance committee can order ... Read More

C++ code to find out if everyone will get ice cream

Arnab Chakraborty
Updated on 29-Mar-2022 08:39:44

467 Views

Suppose, there are three groups of people coming to a party. The first group of people likes butterscotch ice cream and do not like any other flavors of ice cream, the second group of people only dislikes strawberry ice cream and like every other flavor, and the third group likes all kinds of ice cream. Now, there are x people of the first group, y people of the second group, and z people of the third group are coming to a party, and everyone should have at least one icecream of their liking. The party organizers have brought a packs ... Read More

C++ code to find out if a grid is fully accessible

Arnab Chakraborty
Updated on 29-Mar-2022 08:36:58

230 Views

Suppose, we are given a grid that has 2 rows and n columns. A robot is at position (0, 0) in the grid and wants to visit (1, n - 1) by visiting adjacent and corner cells to its current location. We are given the grid in an array of strings, a cell is blocked if it is marked '#' and it is accessible if it is marked '.'. We have to find out if the robot can visit cell (1, n - 1) from the cell (0, 0).So, if the input is like n = 4, grid = {".##.", ... Read More

C++ code to decrease even numbers in an array

Farhan Muhamed
Updated on 30-Jul-2025 15:33:44

321 Views

An array is a group of similar elements stored together in a single variable which take contiguous memory locations. Arrays help us to store and manage multiple values of the same type, like a list of numbers or names.In this article, we will solve a beginner level problem in C++ that involves decreasing all the even numbers in an array by 1. Program to Decrease Even Numbers in an Array How to Check a if Number is Even in C++? C++ Program to Decrease Even Numbers ... Read More

C++ code to find total elements in a matrix

Arnab Chakraborty
Updated on 29-Mar-2022 08:29:08

213 Views

Suppose, we are given a matrix of n rows and m columns. We have to find out the number of elements present in it. We find out the value and display it as output.So, if the input is like n = 20, m = 15, then the output will be 300.StepsTo solve this, we will follow these steps −return n * mExampleLet us see the following implementation to get better understanding −#include using namespace std; #define N 100 int solve(int n, int m) {    return n * m; } int main() {    int n = 20, m = 15;    cout

What are the differences between C++ and Go?

Bhanu Priya
Updated on 23-Mar-2022 10:40:52

372 Views

Let us understand the concepts of C++ and Go before learning the differences between them.GoIt is an open source programming language developed by Google employees, It is intended to be fast compiled, garbage collected, strongly typed, and with explicit support for concurrent programming.The original developers Rob Pike, Robert Griesemer and Ken Thompson started out in the year 2007. It was licensed under the BSD license. In the case of large systems it supports statically typing and scalability.FeaturesThe features of Go are as follows −Language DesignPowerful standard libraryPackage ManagementStatic TypingTesting SupportC-inspired syntaxCompiledSafe and open sourceAdvantagesThe advantages of Go are as follows ... Read More

C++ code to count maximum hay-bales on first pile

Arnab Chakraborty
Updated on 15-Mar-2022 07:03:37

157 Views

Suppose we have an array A with n elements and another value d. A farmer has arranged n haybale piles on the firm. The ith pile contains A[i] hay-bales. Every day a cow can choose to move one hay-bale in any pile to an adjacent pile. The cow can do this on a day otherwise do nothing. The cow wants to maximize the hay-bales in first pile in d days. We have to count the maximum number of hay-bales on the first pile.So, if the input is like d = 5; A = [1, 0, 3, 2], then the output ... Read More

C++ code to find name with O's on Fibonacci positions

Arnab Chakraborty
Updated on 15-Mar-2022 07:01:34

122 Views

Suppose we have a number n. Amal wants to give a name to his pet. He will follow an algorithm. The name will be n characters long. The name will contain uppercase and lowercase letters 'O's and 'o's. The algorithm suggests the i-th letter of the name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n.So, if the input is like n = 10, then the output will be "OOOoOooOoo", because first fibonacci numbers are 1, 2, 3, 5 and so on.StepsTo ... Read More

Advertisements