Server Side Programming Articles - Page 2155 of 2650

Program to convert given number of days in terms of Years, Weeks and Days in C

Sunidhi Bansal
Updated on 18-Oct-2019 07:51:37

4K+ Views

You are given with number of days, and the task is to convert the given number of days in terms of years, weeks and days.Let us assume the number of days in a year =365Number of year = (number of days) / 365Explanation-: number of years will be the quotient obtained by dividing the given number of days with 365Number of weeks = (number of days % 365) / 7Explanation-: number of weeks will be obtained by collecting the remainder from dividing the number of days with 365 and further dividing the result with number of days in a week ... Read More

Program to convert given Matrix to a Diagonal Matrix in C++

Sunidhi Bansal
Updated on 18-Oct-2019 07:47:09

616 Views

Given with the matrix of size nxn the task it to convert any type of given matrix to a diagonal matrix.What is a diagonal MatrixDiagonal matrix is the nxn matrix whose all the non-diagonal elements are zero and diagonal elements can be any value.Given below is the diagram of converting non-diagonal elements to 0.$$\begin{bmatrix}1 & 2 & 3 \4 & 5 & 6 \7 & 8 & 9 \end{bmatrix}\:\rightarrow\:\begin{bmatrix}1 & 0 & 3 \0 & 5 & 0 \7 & 0 & 9 \end{bmatrix}$$The approach is to start one loop for all non-diagonal elements and another loop for diagonal elements ... Read More

Maximum GCD from Given Product of Unknowns in C++

Arnab Chakraborty
Updated on 21-Oct-2019 06:59:29

160 Views

Suppose we two integers N and P. The P is the product of N unknown integers. We have to find the GCD of those integers. There can be different groups of integers possible, that will give the same result. Here we will produce GCD, which is maximum among all possible groups. Suppose N = 3, and P = 24, then different groups will be like {1, 1, 24}, {1, 2, 12}, {1, 3, 8}, {1, 4, 6}, {2, 2, 6}, {2, 3, 4}. The GCDs are: 1, 1, 1, 1, 2, 1. So answer is 2 here.The technique us like, ... Read More

Maximum Consecutive Zeroes in Concatenated Binary String in C++

Arnab Chakraborty
Updated on 17-Oct-2019 13:40:16

465 Views

Suppose we have a binary string of length n, another value say k is given. We have to concatenate the binary string k times. Then we have to find the maximum number of consecutive 0s in the concatenated string. Suppose binary string is “0010010”, and k = 2, then after concatenating the string k times, it will be “00100100010010”. So the maximum number of consecutive 0s is 3.The approach is simple. If the number has all 0s, then the answer will be n * k. If the string contains ones, then the result will be either the max length of ... Read More

How to run Python code on Google Colaboratory?

Pradeep Elance
Updated on 17-Oct-2019 13:25:07

798 Views

Google Colaboratory is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud. It is hosted in google cloud and maintained by Google for the benefit of python coders who want to run and test python scripts using a cloud environment. In this article, we will see how to set up and run a google collaboratory cloud environment.Opening the Python NotebookWe navigate to this google link (https://colab.research.google.com/). It opens up the below screen. We choose the option NEW PYTHON3 NOTEBOOK from the bottom right corner as shown in the diagram below.Python CodeOptionsOn clicking the NEW ... Read More

How to implement Dictionary with Python3

Pradeep Elance
Updated on 17-Oct-2019 13:20:17

278 Views

Dictionaries in python are a type of data structure that map keys to values as a key-value pair. They are one of the frequently used data structures and have many interesting properties. They are presented by enclosing them in a pair of curly brace like below.dict = {'day1':'Mon' ,'day2':'Tue', 'day3':'Wed'}The elements or key-value pairs in the dictionary are represented within single quotes and separated by a colon.Creating a DictionaryWe create a dictionary by assigning values written in the form of a key.ExampleDict1 = {'day1':'Mon' ,'day2':'Tue', 'day3':'Wed'} print(type(dict1)) print(dict1) # Using the dict() method dict2 =dict({('day1', 'Mon'), ('day2', 'Tue'), ('day3', ... Read More

What is Heap queue (or heapq) in Python?

Pradeep Elance
Updated on 17-Oct-2019 13:12:58

308 Views

Heap queue is a special tree structure in which each parent node is less than or equal to its child node.In pythin it is implemented using the heapq module. It is very useful is implementing priority queues where the queue item with higher weightage is given more priority in processing. TheCreate a HeapA heap queue is created by using python’s inbuilt library named heapq. This library has the relevant functions to carry out various operations on heap data structure. Below is a list of these functions.heapify − This function converts a regular list to a heap. In the resulting heap ... Read More

Guide to Install MongoDB with Python in Windows

Pradeep Elance
Updated on 17-Oct-2019 13:08:55

648 Views

Get MongoDBTo install MongoDB on Windows, first, download the latest release of MongoDB from https://www.mongodb.org/downloads. Below is an example of selecting a 64-bit version for windows as a msi installer.Install MongoDBNext, we follow the below steps to install MongoDB. As it is a windows installation using the msi installer, the steps are very straight forward. We choose a complete installation instead of a custom installation.Running the installerHere we run the installer which has been downloaded to our system. The installation starts asking for various steps of confirmation.Choosing a Service ConfigurationWe choose to run the service as a network service user. Clicking ... Read More

Graph Plotting in Python

Pradeep Elance
Updated on 17-Oct-2019 13:03:28

1K+ Views

Python has the ability to create graphs by using the matplotlib library. It has numerous packages and functions which generate a wide variety of graphs and plots. It is also very simple to use. It along with numpy and other python built-in functions achieves the goal. In this article we will see some of the different kinds of graphs it can generate.Simple GraphsHere we take a mathematical function to generate the x and Y coordinates of the graph. Then we use matplotlib to plot the graph for that function. Here we can apply labels and show the title of the ... Read More

Global keyword in Python

Pradeep Elance
Updated on 17-Oct-2019 12:58:23

947 Views

Different variables in a python program have different scope. Depending on where it is declared, the variable may or may not be accessible inside a function. Sometimes we will need to modify a variable that is present inside a function from outside its current scope. In such a scenario we use the global keyword with the variable name.Following are the key points about the global keywordA variable declared outside a function is a global variable by default.We use a global keyword for a variable which is inside a function so that it can be modified.Without the global keyword, the variable ... Read More

Advertisements