Found 26504 Articles for Server Side Programming

Python program to Count Even and Odd numbers in a List

Pavitra
Updated on 11-Jul-2020 11:25:39

6K+ Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list, we need to count even and odd numbers in a list.There are three methods as discussed below−Approach 1 − Using brute-force approachExample Live Demolist1 = [21, 3, 4, 6, 33, 2, 3, 1, 3, 76] even_count, odd_count = 0, 0 # enhanced for loop for num in list1:    #even numbers    if num % 2 == 0:       even_count += 1    #odd numbers    else:       odd_count += 1 print("Even numbers available in the ... Read More

Python Program to convert Kilometers to Miles

Pavitra
Updated on 23-Dec-2019 07:37:08

351 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given distance in kilometers and we need to convert it into milesAs we know that 1 kilometer equals 0.62137 miles.Formula UsedMiles = kilometer * 0.62137Now let’s observe the concept in the implementation below−Example Live Demokilometers = 5.5 # conversion factor as 1 km = 0.621371 miles conv = 0.621371 # calculation miles = kilometers * conv print(kilometers, "kilometers is equal to ", miles, "miles")Output5.5 kilometers is equal to 3.4175405 milesAll the variables are declared in the local scope and their references are seen ... Read More

Python program to convert hex string to decimal

Pavitra
Updated on 23-Dec-2019 07:35:02

527 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a hexadecimal string, we need to convert it into its decimal equivalent.We have two approaches to solve the problem−Brute-force ApproachUsing Built-in moduleBrute-Force MethodHere we take the help of explicit type casting function i.e. integer. This function takes two arguments i.e. hex equivalent and base i.e. (16). This function is used to convert a hexadecimal string to its equivalent decimal in an integer type, which can be further typecasted back to string format.Example Live Demo#input string string = 'F' # converting hexadecimal string ... Read More

C Program for Round Robin scheduling

Sunidhi Bansal
Updated on 23-Dec-2019 07:41:30

9K+ Views

We are given with the n processes with their corresponding burst time and time quantum and the task is to find the average waiting time and average turnaround time and display the result.What is Round Robin Scheduling?Round robin is a CPU scheduling algorithm that is designed especially for time sharing systems. It is more like a FCFS scheduling algorithm with one change that in Round Robin processes are bounded with a quantum time size. A small unit of time is known as Time Quantum or Time Slice. Time quantum can range from 10 to 100 milliseconds. CPU treat ready queue ... Read More

Product of lengths of all cycles in an undirected graph in C++

Sunidhi Bansal
Updated on 23-Dec-2019 07:30:16

229 Views

We are given with the undirected as well as unweighted graph as an input and the task is to find the product of the cycles that are formed in the given and display the result.ExampleInputIn the given figure, there are 8 nodes and out of that 5 nodes are forming cycle including 1, 6, 3, 5, 8 and rest of the node are not included in the cycle. So, the length of the cycle is 5 as it includes 5 node therefore product is 5In the given figure, there are 12 nodes and out of that 11(5 +6) nodes are ... Read More

Priority Queue Introduction in C/C++

Sunidhi Bansal
Updated on 23-Dec-2019 07:25:27

530 Views

A priority queue is a type of queue in which elements are inserted or deleted according to the priorities assigned to them where priority is an integer value that can range between 0-10 where 0 shows the element with the highest priority and 10 shows the element with the lowest priority. There are two rules that are followed for implementing priority queue −Data or element with the highest priority will get executed before the data or element with the lowest priority.If two elements have the same priority than they will be executed in the sequence they are added in the ... Read More

Convert a list to string in Python program

Pavitra
Updated on 23-Dec-2019 07:28:22

241 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given a list iterable, we need to convert it into a string type iterable.There are four approaches to solve the given problem. Let’s see them one by one−Brute-force ApproachExample Live Demodef listToString(s):    # initialize an empty string    str_ = ""    # traverse in the string    for ele in s:       str_ += ele    # return string    return str_ # main s = ['Tutorials', 'Point'] print(listToString(s))OutputTutorialsPointUsing Built-In join() methodExampledef listToString(s):    # initialize an empty string ... Read More

Probability of getting a sum on throwing 2 Dices N times in C++

Sunidhi Bansal
Updated on 23-Dec-2019 07:24:49

348 Views

We are given with the sum and the number of times the pair of dice is thrown as an input and the task is to determine the probability of getting the given sum on throwing a pair of dice N times.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.ExampleInput-: sum = 12, N = 1 Output-: Probability = 1/36 Explanation-: if a pair of dice is thrown once then the combinations will ... Read More

Python program to check if the given string is vowel Palindrome

Pavitra
Updated on 23-Dec-2019 07:17:47

460 Views

In this article, we will learn about the solution to the problem statement given below.Problem statement − We are given string (containing both vowel and consonant letters), remove all consonants, then check if the resulting string is a palindrome or not.Here we first remove all the consonants present in the string. A loop to calculate the divisors by computed by dividing each value from 1 to the minimum computedEach time the condition is evaluated to be true counter is incremented by one.Remove all the consonants in the string. Now we check whether the vowel string is a palindrome or not i.e. ... Read More

Priority Queue using Linked List in C

Sunidhi Bansal
Updated on 23-Dec-2019 07:15:27

4K+ Views

We are given with the data and the priority as an integer value and the task is to create a linked list as per the priority given and display the result.Queue is a FIFO data structure in which the element which is inserted first is the first one to get removed. A Priority Queue is a type of queue in which elements can be inserted or deleted depending upon the priority. It can be implemented using queue, stack or linked list data structure. Priority queue is implemented by following these rules −Data or element with the highest priority will get ... Read More

Advertisements