
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

221 Views
Given an integer variable Number as input. Let us consider an array containing elements in the range 1 to Number in any order. If we perform an operation Number-1 times on an array such thatWe select two elements A and B from the arrayRemove A and B from arrayAdd sum of squares of A and B to the arrayWe will get a single integer value in the end; the goal is to find the maximum possible value for that element.Using Priority QueueIn order to maximize the end result, we will have to choose A and B such that they are ... Read More

268 Views
Given an integer variable Number as input. Let us consider an array containing elements in the range 1 to Number in sorted order. If we perform an operation on an array such that at each step the elements at odd positions are removed. Then the goal is to perform this operation N number of times till only a single element is left. Print that element at the end.Note-: The positioning of elements is such that the array at index 0 is at 1st position and so on.Test Cases for Number of elements in arrayInput Number=1, output = 1Input Number=2, output ... Read More

8K+ Views
Selection Sort is one of the sorting algorithms used to sort data by iterating an array from the beginning and replacing each element with the smallest element in the list. As we move forward the left array is sorted, and the right array is unsorted. Each move places the next smallest to the current position of the index by swapping.Selection Sort Algorithmint arr[5]= { 5,4,2,1,3 };int i, j ;Traverse from index i=0 to i

2K+ Views
We are given an integer number Num as input. The goal is to find the reverse of the number using stack.Stack:- A stack is a data structure in C++ which stores data in LIFO ( Last in First Out) manner. Major operations of stack are-:Declaration-: stack stck; //stck is now a stack variable.Finding Top using top(). Function stck.top() returns reference of top element in the stckRemoving Top using pop(). Function removes topmost element from the stckAdding element to top using push(). Function stck.push( value ) adds item value in stack. Value should be of type stck.Check if staxk is ... Read More

13K+ Views
We are given an integer array Arr[] as input. The goal is to find maximum and minimum elements among the array using recursive methods.Since we are using recursion, we will traverse the whole array till we reach length=1 then return A[0] which forms the base case. Else compare current element with present minimum or maximum and update its value by recursion for later elements.Let us see various input output scenarios for this −Input − Arr= {12, 67, 99, 76, 32};Output − Maximum in the array :99Explanation − Out of all elements 99 is maximum among them.Input − Arr= {1, 0, -99, 9, 3};Output − Minimum ... Read More

2K+ Views
We are given a string containing a binary number. The goal is to find the equivalent decimal number using the recursive method.A binary number can be converted to decimal using following method-: Traverse from LSB to MSB and multiply each with power of 2i Where 0

225 Views
We are given an integer as input. The goal is to print the formula of GCD of n numbers using recursion.We know that the GCD of three numbers say a1, b1 and c1 will be gcd(a1, gcd(b1, c1)).Similarly for more than three numbers, gcd can be obtained by formula as gcd ( a1, gcd(b1, gcd(c1….., gcd(y1, z1)).ExamplesInput − Num = 4;Output − Formula is:GCD(int a3, GCD(int a2, GCD(int a1, int b1)))Input − Num = 6;Output − Formula is: GCD(int a5, GCD(int a4, GCD(int a3, GCD(int a2, GCD(int a1, int b1)))))Approach used in the below program is as followsIn this approach we are using the ... Read More

6K+ Views
We are given an integer as input. The goal is to find whether the input number Num is a palindrome or not using recursion.To check if a number is palindrome, reverse that number and check if both numbers are the same or not. If the reversed number is equal to the original number, then it is palindrome.ExamplesInput − Num = 34212;Output − 34212 is not a Palindrome!Explanation − If we reverse 34212 then we get 21243. 34212 != 21243 hence the input number is not palindrome.Input − Num = 32123;Output − 32123 is Palindrome!Explanation − If we reverse 32123 then we get 32132. 32123!= 32123 ... Read More

2K+ Views
We are given a string containing a number. The goal is to find the equivalent number using the recursive atoi() method. int atoi(const char *str) converts the string argument str to an integer (type int).Example-:Input − Str[] = "58325"Output − The Equivalent decimal is :58325Explanation − The string contains the equivalent number 58325Input − Str[] = "00010"Output − The Equivalent decimal is :1Explanation − The string contains the equivalent number 10.Approach used in the below program is as followsIn this approach we are using the recursive function recurAtoi() which takes input string and its length and for each character convert it to decimal and multiply ... Read More