Predefined Identifiers 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

Predict the Winner in Coin Game in C++

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

349 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

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

Predict the Winner of the Game in C++

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

194 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

Preemptive and Non-Preemptive Scheduling

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

13K+ Views

Preemptive Scheduling is a CPU scheduling technique that works by dividing time slots of CPU to a given process. The time slot given might be able to complete the whole process or might not be able to it. When the burst time of the process is greater than CPU cycle, it is placed back into the ready queue and will execute in the next chance. This scheduling is used when the process switch to ready state.Algorithms that are backed by preemptive Scheduling are round-robin (RR), priority, SRTF (shortest remaining time first).Non-preemptive Scheduling is a CPU scheduling technique the process takes ... Read More

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

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

Print Number with Commas as 1000 Separators in Python

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

501 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

Print First N Distinct Permutations of String Using itertools in Python

Pradeep Elance
Updated on 04-Feb-2020 07:01:25

398 Views

Permutation of a number of objects is the representation of how the updates can be present in different sequences. But sometimes we may have two objects in a series of given objects which are identical. In that case two sequences will become equal. In this article will see how to represent only the unique sequences from a given list of objects.The module itertools have a method called permutations which help us achieve this. To get the unique permutations we take help of the set method which stores only the distinct elements. But before that we get the elements in the ... Read More

Check Prime Number in Python

Pradeep Elance
Updated on 04-Feb-2020 06:52:09

805 Views

Prime numbers play a central role in many e it applications like cryptography. So it is a necessity to check for prime numbers using Python programs in various applications. A prime number is a number which doesn't have any factors other than one and itself. Below will see programs that can find out if a given number is prime or not.ApproachWe take the following approach to decide whether a number is prime or not.Check at the beginning is positive or not. As only positive numbers can be prime numbers.We divide the number with all the numbers in the range of ... Read More

Advertisements