Found 7347 Articles for C++

Minimum removals to make array sum odd in C++

Narendra Kumar
Updated on 23-Dec-2019 06:42:37

165 Views

Problem statementGiven an array arr[] of N integers. We need to write a program to find minimum number of elements needed to be removed from the array, so that sum of remaining element is odd.ExampleIf input array is {10, 20, 30, 5, 7} then we need to remove one element i.e. either 5 or 7 to make array sum oddAlgorithm1. Sum of any number of even numbers is always even 2. Sum of odd numbers of odd numbers is always odd 3. Sum of odd numbers of even times is always even 4. Count the number of odd elements in ... Read More

C++ Program for Shortest Job First (SJF) scheduling(non-preemptive)

Sunidhi Bansal
Updated on 23-Dec-2019 06:52:39

6K+ Views

Given process, the burst time of a process respectively and a quantum limit; the task is to find and print the waiting time, turnaround time and their respective average time using Shortest Job First Scheduling non-preemptive method.What is the shortest job first scheduling?Shortest job first scheduling is the job or process scheduling algorithm that follows the nonpreemptive scheduling discipline. In this, scheduler selects the process from the waiting queue with the least completion time and allocate the CPU to that job or process. Shortest Job First is more desirable than FIFO algorithm because SJF is more optimal as it reduces ... Read More

Minimum removals to make array sum even in C++

Narendra Kumar
Updated on 23-Dec-2019 06:39:21

159 Views

Problem statementGiven an array arr[] of N integers. We need to write a program to find minimum number of elements needed to be removed from the array, so that sum of remaining element is even.ExampleIf input array is {10, 20, 30, 5} then we need to remove one element i.e. 5 to make array sum evenAlgorithm1. Sum of any number of even numbers is always even 2. Sum of odd numbers of odd numbers is always odd 3. Sum of odd numbers of even times is always even 4. Count the number of odd elements in the array. If the ... Read More

C++ Program for Coefficient of variation

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

563 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

78 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

225 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

967 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

245 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

298 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

160 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

Advertisements