Found 26504 Articles for Server Side Programming

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

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

364 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

653 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

136 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

311 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

444 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

237 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

Convex Hull Monotone chain algorithm in C++

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

222 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.Example Live Demo#include #define llu long long int using namespace std; //structure for the given point struct Point {    llu x, y;    bool operator= t && calc_crossproduct(ans[k - 2],       ans[k - 1], A[i - 1])

Convex Hull Graham Scan in C++

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

966 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 Graham Scan, firstly the pointes are sorted to get to the bottommost point. Then the points are traversed in order and discarded or accepted to be on the boundary on the basis of their order.Example#include #include #include using namespace std; struct Point{    int x, y; }; //point reference for sorting other points Point p0; //moving to ... Read More

Advertisements