Server Side Programming Articles - Page 1896 of 2650

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

348 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

190 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

Prefix Sum of Matrix (Or 2D Array) in C++

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

4K+ Views

In this problem, we are given a 2D array of integer values mat[][]. Our task is to print the prefix sum matrix of mat.Prefix sum matrix: every element of the matrix is the sum elements above and left of it. i.eprefixSum[i][j] = mat[i][j] + mat[i-1][j]...mat[0][j] + mat[i][j-1] +... mat[i][0].Let’s take an example to understand the problemInput: arr =[    [4   6   1]    [5   7   2]    [3   8   9] ] Output:[    [4   10   11]    [9   22   25]    [12   33   45] ]To solve this problem, ... Read More

Program to create grade calculator in Python

Pradeep Elance
Updated on 04-Feb-2020 07:15:38

2K+ Views

In Academics it is a common requirement to find the grades of students after an assessment. In this article we will create a Python program which will assign the grades based on the grading criteria. Will call it A grade calculator.Grading criteriaBelow is the grading criteria we have chosen for the program.score >= 90 : "O" score >= 80 : "A+" score >= 70 : "A" score >= 60 : "B+" score >= 50 : "B" score >= 40 : "C"Program ApproachInitialize variables and array to hold the student details including the marks obtained by individual subjects.Define a function to ... Read More

Print number with commas as 1000 separators in Python

Pradeep Elance
Updated on 04-Feb-2020 07:05:34

500 Views

Many times the numbers with three or more digits need to be represented suitably using comma. This is a requirement mainly in the accounting industry as well as in the finance domain. In this article we'll see how Python program can be used to insert a comma at a suitable place. We are aiming to insert comma as a thousand separator.Format FunctionThe format function in python can be used with below settings to achieve this requirement.(f"{num:, d}") : is the format specifier D is the thousand separatorExample - Integers Live Demoprint(f'{1445:, d}') print(f'{140045:, d}')OutputRunning the above code gives us the following ... Read More

Advertisements