Programming Articles - Page 2200 of 3366

Program for K Most Recently Used (MRU) Apps in C++

Sunidhi Bansal
Updated on 23-Dec-2019 11:12:31

1K+ Views

Given a number k and an array arr[n], containing n number of integer elements which are storing the id’s of the opened apps in a system; the task is to show k number of most recently used apps, like when we press alt+tab shows all the recent apps and most recent before the least recent. The position of every id represents different apps in a system −They are as follows −Id in arr[0] is the id of an app which is currently in use.Id in arr[1] is the id of an app which was most recently used.Id in arr[n-1] is ... Read More

Printing Items in 0/1 Knapsack in C++

Sunidhi Bansal
Updated on 23-Dec-2019 11:12:36

1K+ Views

Given weights and values of n items; the task is to print the items according to 0/1 knapsack for the following weights and values in a knapsack of capacity W, to get the maximum total value in the knapsack.What is 0/1 Knapsack?Knapsack is like a bag with only a fixed size or a bag which can handle a certain amount of weight. Each item which is included in a knapsack have some value(profit) and some weight to it. We have to add those weights which will get us the maximum profit according to the total weight a knapsack could hold.So ... Read More

Product of every K’th prime number in an array in C++

Sunidhi Bansal
Updated on 23-Dec-2019 11:04:17

178 Views

Given an array arr[n] containing n prime numbers and k; the task is to find the product of every k’th prime number in an array.Like, we have an array arr[] = {3, 5, 7, 11} and k = 2 so the prime number after every k i.e 5 and 11 we have to find their product which will be 5x11 = 55 and print the result as output.What are prime numbers?A prime number is a natural number which can’t be divided by any other number except 1 or the number itself. Some of the prime numbers are 2, 3, 5, ... Read More

Printing source of a C program itself

Sunidhi Bansal
Updated on 23-Dec-2019 11:01:17

653 Views

Given the task is to print the written C program itself.We have to write a C program which will print itself. So, we can use file system in C to print the contents of the file of which we are writing the code, like we are writing the code in “code 1.c” file, so we open the file in the read mode and read all the contents of the file and print the results on the output screen.But, before opening a file in read mode, we must know the name of the file we are writing code in. So, we ... Read More

Program for Point of Intersection of Two Lines in C++

Sunidhi Bansal
Updated on 02-Dec-2024 00:24:08

4K+ Views

Given points A and B corresponding to line AB and points P and Q corresponding to line PQ; the task is to find the point of intersection between these two lines. Note − The points are given in 2D plane on X and Y coordinates. Here A(a1, a2), B(b1, b2) and C(c1, c2), D(d1, d2) are the coordinates which are forming two distinct lines and P(p1, p2) is the point of intersection. (just for a diagrammatic explanation of the point of intersection) How to find the point of intersection − Let’s take the above figure as − Example So ... Read More

Program to build DFA that starts and end with ‘a’ from input (a, b) in C++

Sunidhi Bansal
Updated on 23-Dec-2019 10:56:18

1K+ Views

Given a DFA string of characters ‘a’ and ‘b’, which should start and end with the character ‘a’ the task is to find whether the string starts and ends with ‘a’ through a DFA.What is DFA(Deterministic Finite Automata)?In theory of computation, a branch of theoretical computer science, Deterministic Finite Automata is a finite state machine which accepts or reject strings of symbols. Deterministic refers to the uniqueness of the computation to run.For finding the string by a DFA and the string should start and end with ‘a’ from the input (a, b). Since there is no concept of memory and ... Read More

Probability of getting at least K heads in N tosses of Coins in C++

Sunidhi Bansal
Updated on 23-Dec-2019 10:52:10

571 Views

Probability is the chances of getting the desired output from the set of data available. The range of probability lie between 0 and 1 where an integer 0 shows the chances of impossibility and 1 indicates certainty.What is probability?Probability in mathematics gives us the tools that tell the uncertainty of the events and reasons. In other words we can say probability deals with calculating the likelihood of a given event’s occurrence, which can be expressed as a number between 1 and 0. For example: the probability of getting a head’s when an unbiased coin is tossed, or getting a 3 ... Read More

Event scheduler in Python

Pradeep Elance
Updated on 23-Dec-2019 10:35:38

2K+ Views

Python gives us a generic scheduler to run tasks at specific times. We will use a module called schedule. In this module we use the every function to get the desired schedules. Below is the features available with the every function..SynatxSchedule.every(n).[timeframe] Here n is the time interval. Timeframe can be – seconds, hours, days or even name of the Weekdays like – Sunday , Monday etc.ExampleIn the below example we will see fetch the price of bitcon in every few seconds by using the schedule module. We also use the api provided by coindesk. For that purpose we will use ... Read More

Adding value to sublists in Python

Pradeep Elance
Updated on 23-Dec-2019 10:35:02

855 Views

Sometimes we need to introduce an additional value to an already existing list. In this article we will see how the new value or values can be inserted into an already existing list by combining with each item of the existing list.Using For LoopIf we take a list which has items of the same length, we can use this method to introduce new values in each of the item of the list. In the below example we are taking a list ofExample Live DemoList = [[10, 20], [14, 8], ['Mon', 'Tue']] print("Given List: " + str(List)) s = "Rise" t = ... Read More

Turtle graphics using Python

Pradeep Elance
Updated on 23-Dec-2019 10:33:05

28K+ Views

Turtle is a Python library to draw graphics. After we import Turtle we can give commands like forward, backward, right, left etc. This commands will draw different shapes when we. When We combine Search commands we can create many nice graphics in the below example we will see some simple scenarios and then some Complex ones where nice graphics is created.Simple Turtle Commandsforward(10)  It moves the turtle (arrow) forward by 10 pixels.backward(5)  It moves the turtle (arrow) backward by 5 pixels right(35)  It moves the turtle (arrow) clockwise by an angle of 35 degrees.left(55)  It moves the turtle (arrow) counter-clockwise by ... Read More

Advertisements