Found 26504 Articles for Server Side Programming

Correct the Random Pointer in Doubly Linked List in C++

Ayush Gupta
Updated on 05-Feb-2020 07:14:03

171 Views

In this tutorial, we will be discussing a program to correct the random pointer in a doubly linked list.For this we will be provided with a doubly linked list with one node having a random pointer. Our task is to rectify the element to whom the pointer should be pointing i.e the element next to it.Example Live Demo#include using namespace std; //node structure for doubly linked list struct node {    int data;    node* next;    node* prev; }; //new node creation node* newNode(int data){    node* temp = new node;    temp->data = data;    temp->next = temp->prev ... Read More

Practice questions on Arrays in C++

sudhir sharma
Updated on 04-Feb-2020 07:48:37

1K+ Views

Array is a data structure that store data in the contagious memory location.Declaring arraysDeclaring arrays is done by the following syntax : int 1D[] - for 1-D array int 2D[][] - for 2-D arrayIf you initialize an array with lesser number of elements, rest are initialized with 0.Memory address of elements of the array1-D array : address[i] = baseAddress + i*size 2-D array (row major) : address[i][j] = baseAddress + (i*n + j) * sizeNow, let’s see some practice problemPredict the output of the following code snippetint arr[5] = {6, 9}; for(int i = 0; i

Practice questions on Strings in C++

sudhir sharma
Updated on 04-Feb-2020 07:46:23

682 Views

String is an important part of programming. Strings are the array of character types. In competitive exams like GATE also it is an important topic. So let’s discuss some key points about string and then we will proceed to some questions that will help you clear your concepts about string.String in a programming language can be stored in two different ways. They are using character array (char str[size]) and using a pointer that will point to the string (char * ch = “Hello”). There are some important things related to the use of the character array and pointer to a ... Read More

Practice Questions on Time Complexity Analysis in C++

sudhir sharma
Updated on 02-Aug-2021 12:05:47

10K+ Views

Time complexity of any algorithm is the time taken by the algorithm to complete. It is an important metric to show the efficiency of the algorithm and for comparative analysis. We tend to reduce the time complexity of algorithm that makes it more effective.Example 1Find the time complexity of the following code snippetsfor(i= 0 ; i < n; i++){    cout

Precision of floating point numbers in C++ (floor(), ceil(), trunc(), round() and setprecision())

Tapas Kumar Ghosh
Updated on 06-Jun-2025 19:32:33

8K+ Views

Precision of floating point numbers is the accuracy upto which a floating point number can hold the values after decimal. For example, 10/6 = 1.6666666… these have recurring decimals which can take infinite memory spaces to be stored. To avoid memory overflow in such cases the compiler set a precision limit to the number. For float values in C++, the precision is set to 6-7 digit after that if the decimal recurs it will discard the value. So, to avoid any major losses when this discarding takes place there are methods and libraries that support the precision is float values. ... Read More

Predefined Identifier __func__ in C

sudhir sharma
Updated on 04-Feb-2020 07:30:13

2K+ Views

Identifier is the name given to an entity in programming to identify it in the program.Generally, identifiers are created by the programmer for efficient working but there are some predefined identifiers that are inbuilt in programming. For example, cout, cin, etc.Here, we will see one of these predefined identifiers of C programming language which is __func__.The formal definition of __func__ is  −“The identifier __func__ shall be implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declarationstatic const char __func__[] = “function-name”;appeared, where function-name is the name of the lexically-enclosing function.”C program The ... Read More

Programs for printing pyramid patterns in Python

Pradeep Elance
Updated on 04-Feb-2020 07:35:31

2K+ Views

Taking advantage of the for loop and range function in python, we can draw a variety of for pyramid structures. The key to the approach is designing the appropriate for loop which will leave both vertical and horizontal space for the position of the symbol we choose for drawing the pyramid structure.Pattern -1We draw a right angle based pattern.Example Live Demodef pyramid(p):    for m in range(0, p):       for n in range(0, m+1):          print("* ", end="")       print("\r") p = 10 pyramid(p)OutputRunning the above code gives us the following result −* * ... Read More

Predict the winner in Coin Game in C++

sudhir sharma
Updated on 04-Feb-2020 07:23:59

340 Views

In this game, there are two players X and Y. our task is to predict who will win the game if both play optimally and X starts the game.GameIn the coin game, there are two piles with N and M number of coins. One of the players chooses any one of the piles for the game. Then the task is to divide the piles into two halves till any one player cannot further divide the piles.Let’s take an example to understand the problem, Input: M = 2 , N = 2 Output:XExplanation - X starts the game and choose M pile(both ... Read More

Predict the winner of the game on the basis of the absolute difference of sum by selecting numbers in C++

sudhir sharma
Updated on 04-Feb-2020 07:20:06

177 Views

In this problem, we are given an array of n numbers. And there are two players X and Y. Our task is to predict the winner of the game.For player X to win the absolute difference of the sum of numbers by X and Y should be a multiple of 4. If it is not divisible by 4, then Y wins. Player X starts the game.Let’s take an example to understand the problem, Input: a[] = {3 6 9 12} Output: X Explaination: X selects 3 and 6 Y selects 12 and 9 |3+6 - 12+9| = 12, 12 is ... Read More

Program to make Indian Flag in Python

Pradeep Elance
Updated on 04-Feb-2020 07:22:08

3K+ Views

Python’s libraries to draw graphs has very extensive features which can not only give us charts but also give us flexibility to draw other diagrams like flags. In that sense those modules have an artistic touch. In this article we will see how to draw the Indian flag using the libraries numpy and matplotlib.AppraochWe create three rectangles of same width and draw them with appropriate colours and borders.Use pyplot function to draw the circle of the Ashok Chakra at the center of the middle rectangle.Use numpy and matplotlib to draw the 24 lines inside the Ashok Chakra.In all the above ... Read More

Advertisements