Found 7197 Articles for C++

Minimum removals to make array sum even in C++

Ravi Ranjan
Updated on 12-Jun-2025 17:20:06

258 Views

In this article, we have an array arr[] of N integers. Our task is to write a program to find the minimum number of elements needed to be removed from the given array so that the sum of the remaining elements is even. Example The following example demonstrates the minimum number of elements we need to remove from the array for the sum to be even: Input: arr = {12, 23, 40, 53, 17} Output: 1 Input: arr = {20, 11, 13, 40, 24} Output: 0 The explanation of ... Read More

C++ Program for Coefficient of variation

Sunidhi Bansal
Updated on 23-Dec-2019 06:36:06

683 Views

We are given with an array of float values of size n and the task is to find the coefficient of variation and display the result.What is the coefficient of variation?In statistic measure, coefficient of variation is used to find the range of variability through the data given. In terms of finance, coefficient of variation is used to find the amount of risk involved with respect to the amount invested. If the ratio between standard deviation and mean is low then the risk involved in the investment is also low. Coefficient of variation is the ratio between standard deviation and ... Read More

Minimum removals in a number to be divisible by 10 power raised to K in C++

Narendra Kumar
Updated on 23-Dec-2019 06:36:22

149 Views

Problem statementGiven two positive integers N and K. Find the minimum number of digits that can be removed from the number N such that after removals the number is divisible by 10K. Print -1 if it is impossible.ExampleIf N = 10203027 and K = 2 then we have to remove 3 digits. If we remove 3, 2 and 7 then number become 10200 which is divisible by 102Algorithm1. Start traversing number from end. If the current digit is not zero, increment the counter variable, otherwise decrement variable K 2. If K is zero, then return counter as answer 3. After ... Read More

C++ Program for Expressionless Face Pattern printing

Sunidhi Bansal
Updated on 23-Dec-2019 06:33:07

315 Views

Given a number n; the task is to create the Expressionless face pattern upto n lines and display the results. Expressionless face is created using special characters, expressionless face using special character seems like: “*_*”.ExampleInput-: n = 6 Output-:Input-: n = 8 Output-: AlgorithmStart Step 1-> In function print_stars(int i)    Loop For j = 1 and j In function print_pattern(int rows)    Loop For i = 1 and i In function int main()    Declare and set rows = 8    Call print_pattern(rows) StopExample Live Demo#include using namespace std; //function to print stars void print_stars(int i) {    for (int j = 1; j

Reverse a String (Recursive) C++

Ajay yadav
Updated on 23-Dec-2019 06:30:31

1K+ Views

Recursion is simply the way toward rehashing things in a self-comparative way. In programming dialects, if a program enables you to call a capacity inside a similar capacity, at that point, it is known as a recursive call of the capacity. You can switch a string utilizing the recursive capacity as appeared in the accompanying project.Example Live Demo#include using namespace std; void reverse(string str){    if(str.size() == 0){       return;    }    reverse(str.substr(1));    cout

Minimum removals from array to make max – min <= K in C++

Narendra Kumar
Updated on 23-Dec-2019 06:32:46

372 Views

Problem statementGiven N integers and K, find the minimum number of elements that should be removed such that Amax - Amin

Printing Pyramid in C++

Ajay yadav
Updated on 23-Dec-2019 06:28:19

436 Views

This article yields a “pyramid-like structure” as an output using the C++ programming code. In which the pyramid height and space are being determined by traversing double for loop constructs as following;Example Live Demo#include using namespace std; int main() {    int space, rows=6;    for(int i = 1, k = 0; i

Minimum removal to make palindrome permutation in C++

Narendra Kumar
Updated on 23-Dec-2019 06:27:04

246 Views

Problem statementGiven a string S, we have to find minimum characters that we can remove to make any permutation of the string S a palindromeExampleIf str = “abcdba” then we remove to 1 character i.e. either ‘c’ or ‘d’.Algorithms1. There can be two types of a palindrome, even length, and odd length palindromes 2. We can deduce the fact that an even length palindrome must have every character occurring even number of times 3.An odd palindrome must have every character occurring even number of times except one character occurring odd number of time 4. Check the frequency of every character ... Read More

Reverse a String (Iterative) C++

Ajay yadav
Updated on 23-Dec-2019 06:24:14

386 Views

There are many ways defined to reverse a string in the C++ code including stack, In-place, and iteration. In this sample, a simple string will be reversed iteratively with the following algorithm;AlgorithmSTART    Step-1: Input the string    Step-2: Get the length of the string using length() method    Step-3: Swap the last character to first using for loop    Step-4: Print ENDIncompatibility of the above calculation, the accompanying code in c++ language tried as following;Example Live Demo#include using namespace std; void strReverse(string& str){    int n = str.length();    // Swap character starting from two    cout

Minimum number of stops from given path in C++

Narendra Kumar
Updated on 23-Dec-2019 06:23:05

170 Views

Problem statementThere are many points in two-dimensional space which need to be visited in a specific sequence.Path from one point to other is always chosen as shortest path and path segments are always aligned with grid lines.We are given the path which is chosen for visiting the points. We need to tell the minimum number of points that must be needed to generate given paths.Algorithm1. We can solve this problem by observing the pattern of movement when visiting the stop 2. If we want to take the shortest path from one point to another point, then we will move in ... Read More

Advertisements