Found 7197 Articles for C++

Find the Nth_Non_Square_Number using C++

Prateek Jangid
Updated on 23-Nov-2021 10:35:55

238 Views

We all know about the numbers that are not square of any number like 2, 3, 5, 7, 8, etc. There are Nth numbers of non-square numbers, and it is impossible to know every number. So In this article, we will explain everything about the square-free number or non-square number and what are the ways to find Nth non-square number in C++.Nth Non-Square NumberA number is said to be a perfect square if it is a square of an integer. Some example of perfect square numbers are −1 is square of 1 4 is square of 2 9 is square ... Read More

Merge Sort using Multithreading in C++

Sunidhi Bansal
Updated on 05-Nov-2021 07:04:34

4K+ Views

We are given an unsorted integer array. The task is to sort the array using merge sort technique implemented via Multi-threadingMerge SortMerge sort is a sorting technique which is based on divide and conquer technique where we divide the array into equal halves and then combine them in a sorted manner.Algorithm to implement merge sort ischeck if there is one element in the list then return the element.Else, Divide the data recursively into two halves until it can’t be divided further.Finally, merge the smaller lists into new lists in sorted order.Multi-ThreadingIn the operating system, Threads are the lightweight process which ... Read More

Merge Sort Tree in C++

Sunidhi Bansal
Updated on 05-Nov-2021 07:20:07

661 Views

We are given an integer array, a set of segment start and end pointers and a key value and the problem statement here is to find all the values in the given range which are smaller than or equal to the given key value.Let us understand with exampleInput − arr[] = {7, 8 , 1, 4 , 6 , 8 , 10 }Segment 1: start = 2, end = 4, k = 2Segment 2: start = 1, end = 6, k = 3Output − Count of number which are smaller than or equal to key value in the given range are 2 ... Read More

Recursive sum of digits of a number is prime or no in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:40:46

602 Views

Given an integer variable number as input. The goal is to calculate the sum of digits of the input number and check if that sum is prime or not. Do this till the obtained number with sum of digits becomes a single digit number. Check if that number is prime or not. If the input number is 123 than the sum of digits will be 1+2+3=6 which is non-prime and also 6 is a single digit number.Let us see various input output scenarios for thisInput − number=12341Output − Recursive sum of digits of a number is PRIMEExplanation −1+2+3+4+1=111+1=22 is a prime number.Input − ... Read More

Recursive sum of digits of a number formed by repeated appends in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:36:06

403 Views

Given two integers ‘number’ and ‘repeat’ as input. The goal is to calculate the sum of digits of the input number repeated ‘repeat’ number of times until the sum becomes a single digit. Do this till the obtained number with sum of digits becomes a single digit number. If the input number is 123 and repeat=2 than the sum of digits of 123123 will be 1+2+3+1+2+3=12 which is not a single digit number. Now the sum of digits of 12 is 1+2=3. Output will be 3Let us see various input output scenarios for thisInput − number=32 repeat=3Output − Recursive sum of digits ... Read More

Recursively print all sentences that can be formed from list of word lists in C++

Sunidhi Bansal
Updated on 03-Nov-2021 08:14:36

544 Views

Given a list of words. The goal is to create all possible sentences that can be formed by taking words from the list using a recursive approach. You can only take one word at a time from both the lists.Let us see various input output scenarios for thisInput −sentence[row][col] = {{"I", "You"},    {"Do", "do not like"},    {"walking", "eating"}}Output   −I Do walking I Do eating I like walking I like eating You Do walking You Do eating You like walking You like eatingExplanation − Taking one word from each list in sentence[0-2] gives above sentences.Input −sentence[row][col] = {{"work", "live"}, {"easy", "happily"}}Output −work ... Read More

Rotate a matrix by 90 degree without using any extra space in C++

Sunidhi Bansal
Updated on 03-Nov-2021 08:41:32

539 Views

We are given a 2-D array that will be used to form a matrix pattern. The task is to rotate a matrix by 90 degrees in an anti-clockwise direction such that the first row becomes the first column, second row becomes second column and third becomes third column and the challenge is that we don’t have to use any extra space.Let us see various input output scenarios for this −Input −int arr[row_col_size][row_col_size] = { { 5, 1, 4},    { 9, 16, 12 },    { 2, 8, 9}}Output   −Rotation of a matrix by 90 degree without using any extra space ... Read More

Rotate a matrix by 90 degree in clockwise direction without using any extra space in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:23:33

3K+ Views

We are given a 2-D array that will be used to form a matrix pattern. The task is to rotate a matrix by 90 degrees in a clockwise direction such that the last row becomes the first column, second row becomes second column and first becomes third column and the challenge is that we don’t have to use any extra space.Let us see various input output scenarios for this −Input −int arr[row_col_size][row_col_size] = { { 5, 1, 4},    { 9, 16, 12 },    { 2, 8, 9}}Output −Rotation of a matrix by 90 degree in clockwise direction without using any ... Read More

Refactorable number in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:19:18

167 Views

We are given an integer type value, let's say, number. The task is to check whether the given number is Refactorable or not. If yes print that the number is a refactorable number else print not possible.What is a Refactorable Number?A number is refactorable when it is divisible by its total count of factors available. For example, number 9 is refactorable as it has a total number of factors i.e. 3(1, 3, 9) and 9 is divisible by 3 hence its a refactorable number.Let us see various input output scenarios for this −Input − int number = 9Output − It is a ... Read More

Rearrange characters in a string such that no two adjacent are same in C++

Sunidhi Bansal
Updated on 03-Nov-2021 07:13:17

1K+ Views

We are given a string, let's say, str of any given length. The task is to rearrange the given string in such a manner that there won't be the same adjacent characters arranged together in the resultant string.Let us see various input output scenarios for this −Input − string str = "itinn"Output − Rearrangement of characters in a string such that no two adjacent are same is: initn.Explanation − We are given a string type variable let’s say, str. Now we will rearrange the characters of an input string in such a manner that no two same characters occur at the same position ... Read More

Advertisements