Programming Articles - Page 2123 of 3363

Convert to Strictly increasing integer array with minimum changes in C++

Ayush Gupta
Updated on 29-Jan-2020 07:43:14

214 Views

In this tutorial, we will be discussing a program to convert to strictly increasing integer array with minimum changes.For this we will be provided with an array. Our task is to change the elements of the array to be in strictly increasing order by minimum number of changes in the elements.Example Live Demo#include using namespace std; //calculating number of changes required int remove_min(int arr[], int n){    int LIS[n], len = 0;    for (int i = 0; i < n; i++)    LIS[i] = 1;    for (int i = 1; i < n; i++) {       ... Read More

Converting one string to other using append and delete last operations in C++

Ayush Gupta
Updated on 29-Jan-2020 07:49:47

151 Views

In this tutorial, we will be discussing a program to convert one string to other using append and delete last operations.For this we will be provided with two strings. Our task is to calculate whether the first string can be converted into the second one by performing k operations of append and delete last element.Example#include using namespace std; //checking if conversion between strings is possible bool if_convert(string str1, string str2, int k){    if ((str1.length() + str2.length()) < k)    return true;    //finding common length of both string    int commonLength = 0;    for (int i = ... Read More

Converting Roman Numerals to Decimal lying between 1 to 3999 in C++

Ayush Gupta
Updated on 29-Jan-2020 07:40:25

394 Views

In this tutorial, we will be discussing a program to converting roman numerals to decimal lying between 1 to 3999.For this we will be provided with a random roman numeral. Our task is to convert the given roman numeral into its decimal equivalent.Example Live Demo#include using namespace std; //calculating the decimal value int value(char r){    if (r == 'I')    return 1;    if (r == 'V')    return 5;    if (r == 'X')    return 10;    if (r == 'L')    return 50;    if (r == 'C')    return 100;    if (r == 'D')   ... Read More

Convex Hull Jarvis’s Algorithm or Wrapping in C++

Ayush Gupta
Updated on 29-Jan-2020 07:37:54

681 Views

In this tutorial, we will be discussing a program to find the convex hull of a given set of points using Jarvis’s Algorithm.Convex hull is the smallest polygon convex figure containing all the given points either on the boundary on inside the figure.In Jarvis’s algorithm, we select the leftmost point and keep wrapping points moving in the clockwise direction.Example Live Demo#include using namespace std; //structure of the point struct Point{    int x, y; }; //calculating the position of the points int cal_orientation(Point p, Point q, Point r){    int val = (q.y - p.y) * (r.x - q.x) - ... Read More

Converting seconds into days, hours, minutes and seconds in C++

Ayush Gupta
Updated on 29-Jan-2020 07:35:56

1K+ Views

In this tutorial, we will be discussing a program to convert seconds into days, hours, minutes and seconds.For this we will be provided with a random number of seconds. Our task is to convert it into proper number of days, hours, minutes and seconds respectively.Example Live Demo#include using namespace std; //converting into proper format void convert_decimal(int n) {    int day = n / (24 * 3600);    n = n % (24 * 3600);    int hour = n / 3600;    n %= 3600;    int minutes = n / 60 ;    n %= 60;    int seconds = n;    cout

All combinations of strings that can be used to dial a number in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 07:43:50

162 Views

With respect of a given number, display or print all possible combinations of strings that can be implemented to dial the given number in a phone with the help of following pecifications.In the given phone, we can dial, 2 implementing A or B or C, 3 implementing D or E or F, ……………….8 implementing T or U or V, 9 implementing W or X or Y or Z, 1 implementing only 10 implementing 0.For example if 89, is the given phone number, the program should printTW, TX, TY, TZ, UW, UX, UY, UZ, VW, VX, VY, VZ#include #include ... Read More

Some Interesting Observations about C/C++ Ternary Operator

Arnab Chakraborty
Updated on 29-Jan-2020 07:29:59

332 Views

We know that ternary operator is implemented instead of if..else clause. It is denoted by ?: . '?' symbol is equivalent to if part and ':' is equivalent to else part. The following 3 programs explain some interesting observation in case of ternary operator.The following program is able to compile without any error. Ternary expression’s return type is expected to be float (as that of exp2) and exp3 (i.e. literal zero - int type) is able to implicitly convert to float.#include using namespace std; int main(){    int test1 = 0;    float fvalue = 3.111f;    cout

C vs BASH Fork bomb in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 07:25:12

482 Views

It is already cleared that the BASH fork bomb is much more powerful than its version of C program. The main cause is that in BASH the created process is detached from the parent. If the parent process (the one we initially started) is destroyed or killed, the remaining or rest of the processes live on. But in case of the C implementation, the listed child processes die automatically if the parent is destroyed or killed. A script is responsible to communicate with the system directly.The fork bomb program in C can be updated or modified. We can be able ... Read More

Coordinates of rectangle with given points lie inside in C++

Ayush Gupta
Updated on 29-Jan-2020 07:30:11

253 Views

In this tutorial, we will be discussing a program to find the coordinates of rectanglewith given points lying inside.For this we will be provided with some coordinate points. Our task is to find the smallest rectangle such that all the points lie inside it and it should have its sides parallel to the coordinate axis.Example Live Demo#include using namespace std; //calculating the coordinates of smallest rectangle void print_rectangle(int X[], int Y[], int n){    //finding minimum and maximum points    int Xmax = *max_element(X, X + n);    int Xmin = *min_element(X, X + n);    int Ymax = *max_element(Y, ... Read More

Convex Hull using Divide and Conquer Algorithm in C++

Ayush Gupta
Updated on 29-Jan-2020 07:28:58

1K+ Views

In this tutorial, we will be discussing a program to find the convex hull of a given set of points.Convex hull is the smallest polygon convex figure containing all the given points either on the boundary on inside the figure.In this program, we will use brute force to divide the given points into smaller segments and then finally merging the ones that follow on to construct the convex hull.Example Live Demo#include using namespace std; //storing the center point of polygon pair mid; //calculating the quadrant of //a particular point int quad(pair p){    if (p.first >= 0 && p.second >= 0) ... Read More

Advertisements