Server Side Programming Articles - Page 2171 of 2650

Finding the vertex, focus and directrix of a parabola in Python Program

Pavitra
Updated on 26-Sep-2019 07:46:33

189 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementThe standard form of a parabola equation is y=ax^2+bx+c. Input the values of a, b and c, our task is to find the coordinates of the vertex, focus and the equation of the directrix.The vertex of a parabola is the coordinate from which it takes the sharpest turn whereas y=a is the straight-line used to generate the curve.A directrix a fixed line used in describing a curve or surface.Now let’s see the implementation −Example Live Demodef findparabola(a, b, c):    print ("Vertex: (" , (-b ... Read More

Find the perimeter of a cylinder in Python Program

Pavitra
Updated on 26-Sep-2019 07:43:38

429 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementInput diameter and height, find the perimeter of a cylinder.Perimeter is nothing but the side view of a cylinder i.e. a rectangle.Therefore Perimeter= 2 * ( h + d )here d is the diameter of the cylinderh is the height of the cylinderNow let’s see the implementationExample Live Demo# Function to calculate the perimeter of a cylinder def perimeter( diameter, height ) :    return 2 * ( diameter + height ) # main diameter = 5 ; height = 10 ; print ("Perimeter = ... Read More

Python Program for Find sum of Series with the n-th term as n^2 – (n-1)^2

Pavitra
Updated on 26-Sep-2019 07:34:20

336 Views

In this article, we will learn about the solution to the problem statement given below:Problem statementWe are given an integer input n and we need to sum of all n terms where the n-th term in a series as expressed below −Tn = n2 - (n-1)2We have direct formulas for computing the sum which includes the squared muktiolicaion of n which involves more time complexity . To reduce that we usr modular multiplication approach hereNow let's see the implementation −Example Live Demo# Python program to find sum of given # series. mod = 1000000007 def findSum(n):    return ((n % mod) ... Read More

Python Program for Find sum of odd factors of a number

Pavitra
Updated on 26-Sep-2019 07:32:00

709 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementGiven a number input n, the task is to Find the sum of odd factors of a number.Here we first need to eliminate all the even factors.To remove all even factors, we repeatedly divide n till it is divisible by 2. After this step, we only get the odd factors of the number.Below is the implementation −Example Live Demoimport math def sumofoddFactors( n ):    #prime factors    res = 1    # ignore even factors    while n % 2 == 0:     ... Read More

Python Program for Find reminder of array multiplication divided by n

Pavitra
Updated on 26-Sep-2019 07:25:13

775 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementGiven multiple numbers and a number input n, we need to print the remainder after multiplying all the number divisible by n.ApproachFirst, compute the remainder like arr[i] % n. Then multiply this remainder with the current result.After multiplication, again take the same remainder to avoid overflow. This is in accordance with distributive properties of modular arithmetic.( a * b) % c = ( ( a % c ) * ( b % c ) ) % cExample Live Demodef findremainder(arr, lens, n):    mul = ... Read More

Python Program for Find minimum sum of factors of number

Pavitra
Updated on 26-Sep-2019 07:18:50

694 Views

In this article, we will learn about the solution to the problem statement given below −Problem statementGiven a number input , find the minimum sum of factors of the given number.Here we will compute all the factors and their corresponding sum and then find the minimum among them.So to find the minimum sum of the product of number, we find the sum of prime factors of the product.Here is the iterative implementation for the problem −Example Live Demo#iterative approach def findMinSum(num):    sum_ = 0    # Find factors of number and add to the sum    i = 2    while(i * i

Python Program for Find largest prime factor of a number

Pavitra
Updated on 26-Sep-2019 07:16:48

4K+ Views

In this article, we will learn about the solution to the problem statement given below −Problem statementGiven a positive integer n. We need to find the largest prime factor of a number.ApproachFactorise the given number input by dividing it with the divisor of a number.Now keep updating the maximum prime factor.Example Live Demoimport math def maxPrimeFactor(n):    # number must be even    while n % 2 == 0:       max_Prime = 2       n /= 1    # number must be odd    for i in range(3, int(math.sqrt(n)) + 1, 2):       while n ... Read More

Check if a directed graph is connected or not in C++

Arnab Chakraborty
Updated on 25-Sep-2019 14:54:52

2K+ Views

To check connectivity of a graph, we will try to traverse all nodes using any traversal algorithm. After completing the traversal, if there is any node, which is not visited, then the graph is not connected.For the directed graph, we will start traversing from all nodes to check connectivity. Sometimes one edge can have only outward edge but no inward edge, so that node will be unvisited from any other starting node.In this case the traversal algorithm is recursive DFS traversal.Input − Adjacency matrix of a graph0100000100000111000001000Output − The Graph is connected.Algorithmtraverse(u, visited) Input: The start node u and the ... Read More

Python Program for Fibonacci numbers

Pavitra
Updated on 25-Sep-2019 14:18:17

660 Views

In this article, we will learn about the solution and approach to solve the given problem statement.Problem statement −Our task to compute the nth Fibonacci number.The sequence Fn of Fibonacci numbers is given by the recurrence relation given belowFn = Fn-1 + Fn-2with seed values (standard)F0 = 0 and F1 = 1.We have two possible solutions to the problemRecursive approachDynamic approachApproach 1 −Recursive ApproachExample Live Demo#recursive approach def Fibonacci(n):    if n

Check if a binary string has two consecutive occurrences of one everywhere in C++

Arnab Chakraborty
Updated on 25-Sep-2019 14:03:49

226 Views

Here we will see another interesting problem. We have to write a code that accepts a string, which has following criteria.Every group of consecutive 1s, must be of length 2every group of consecutive 1s must appear after 1 or more 0sSuppose there is a string like 0110, this is valid string, whether 001110, 010 are not validHere the approach is simple. we have to find the occurrences of 1, and check whether it is a part of sub-string 011 or not. If condition fails, for any substring then return false, otherwise true.Example Live Demo#include using namespace std; bool isValidStr(string str) ... Read More

Advertisements