Hafeezul Kareem

Hafeezul Kareem

259 Articles Published

Articles by Hafeezul Kareem

Page 15 of 26

Distributing all balls without repetition in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 290 Views

In this tutorial, we are going to learn how to distribute n balls for k students without hurting anyone.The idea is simple, we have n balls in different colors that need to be distributed to the students. We don't have to give more than one ball of the same color to any student. If it is possible for a student to get more than one ball of the same color, then distribution should not happen.Let's see an example.Inputn = 10 k = 5 ballsColors = "rrrgbrbgbr"OutputYesNo color is more than the number of students (k). So, no student will get ...

Read More

Digits of element wise sum of two arrays into a new array in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 325 Views

In this tutorial, we are going to write a program that finds the sun of two array elements and store them into a separate array.We have given two arrays and we need to add the corresponding index elements from the two arrays. If the sum is not single digits, then extract the digits from the number and store them in the new array.Let's see an example.Inputarr_one = {1, 2, 32, 4, 5} arr_two = {1, 52, 3}Output2 5 4 3 5 4 5Let's see the steps to solve the problem.Initialize two arrays with dummy data.We are using the vector to ...

Read More

Digital Root (repeated digital sum) of the given large integer in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 1K+ Views

In this tutorial, we are going to learn how to find the digital root of a given number.The digital root is the sum of a number of digits (until the sum of the digits becomes a single digit).We are given an integer in string format. And we have to find the sum of the digits repeatedly until the sum becomes a single digit.Let's see the steps to solve the problem.Initialize an integer in the string format.Iterate through the number and add each digit to the sum variable.If the sum is 0, then print 0.Else if the sum is divisible by ...

Read More

Different substrings in a string that start and end with given strings in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 368 Views

In this tutorial, we are going to write a program that finds the total number of substrings that starts and ends with the given strings.We are given one string and two substrings. We need to find the different substrings count that starts and ends with the given two substrings. Let's see an example.Inputstr = "getmesomecoffee" start = "m" end = "e"Output6There are a total of 6 different substrings in the given string. They are me, mesome, mesomemecoffe, mesomemecoffee, mecoffe, mecoffee.Let's see the steps to solve the problem.Initialize the strings.Iterate over the str and find the start and end substrings indexes. ...

Read More

Different possible marks for n questions and negative marking in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 392 Views

In this tutorial, we are going to write a program that finds different possible marks for the given n questions with positive and negative marking.Let's say we have 10 questions and each carries 2 marks for correct answers and -1 marks for a negative answer. Our aim is to find all the possible ways in which a student can score in the exam.Let's see the steps to solve the problem.Initialize the number of questions, positive marks for the correct answer and negative marks for the wrong answer.Initialize a set to store the possible marks.Write two inner loops from 0 to ...

Read More

Diagonal of a Regular Pentagon in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 249 Views

In this tutorial, we are going to learn how to find the diagonal of a regular pentagon.We have to find the length of the diagonal of the regular pentagon using the given side. The length of the diagonal of a regular pentagon is 1.22 * s where s is the side of the pentagon.ExampleLet's see the code. Live Demo#include using namespace std; float pentagonDiagonal(float s) {    if (s < 0) {       return -1;    }    return 1.22 * s; } int main() {    float s = 7;    cout

Read More

Diagonal of a Regular Heptagon in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 180 Views

In this tutorial, we are going to learn how to find the diagonal of a regular heptagon.We have to find the length of the diagonal of the regular heptagon using the given side. The length of the diagonal of a regular heptagon is 1.802 * s where s is the side of the heptagon.ExampleLet's see the code. Live Demo#include using namespace std; float heptagonDiagonal(float s) {    if (s < 0) {       return -1;    }    return 1.802 * s; } int main() {    float s = 7;    cout

Read More

Determine the position of the third person on regular N sided polygon in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 184 Views

In this tutorial, we are going to learn how to find the position of a third person on a regular N-sided polygon.We have given a regular N-sided polygon. And there are two persons on two different points already. Our task is to find the third point to place the third person such that the distance between the first two persons and the third person is minimized.Let's see the steps to solve the problem.Initialize the N and two points A and B.Initialize the position of the third person, and the minimum sum to find the position.Iterate from 1 to N.If the ...

Read More

Deserium Number with examples in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 186 Views

In this tutorial, we are going to learn about the deserium numbers with examples.The number whose sum of pow(digit, digitsCount) is equal to the given number is called Deserium number.Let's see the steps to find whether the given number is deserium number or not.Initialize the number.Find the digits count of the number.Initialize a variable to store the sum.Iterate until the number is less than 0.Get the last digit by diving the number with 10.Add the pow(digit, digitsCount) to the sum.If the sum is equal to the number, then it is deserium number else it is not.ExampleLet's see the code. Live Demo#include ...

Read More

Depth of an N-Ary tree in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 27-Jan-2021 1K+ Views

In this tutorial, we are going to learn how to find the depth of the n-ary tree.An n-ary tree is a tree in which each node of the tree has no more than n child nodes.We have to find the depth of the n-ary tree. We will be using the vector to store the children of each node in the tree.Let's see the steps to solve the problem.Initialize the tree with dummy data.Write a recursive function to find the depth of the n-ary tree.Initialize a variable to store the max depth of the tree.Iterate over the children of each node.The ...

Read More
Showing 141–150 of 259 articles
« Prev 1 13 14 15 16 17 26 Next »
Advertisements