Given a number N we have to find the N-th even number.Even numbers are the numbers which are completely divided by 2 and their remainder is zero. Like 2, 4, 6, 8, 10, ….If we closely observe the list of even numbers we can also represent them as2*1=2, 2*2=4, 2*3=6, 2*4=8, ….2*N.So, to solve the problem we can simply multiply the number N with 2, so the result will be the number which is divisible by 2, i.e. the even number.ExampleInput: n = 4 Output: 8 The first 4 even numbers will be 2, 4, 6, 8, .. Input: ... Read More
Given with a number N the task is to check whether the number is a pentagonal number or not. Numbers that can be arranged to form a pentagon is a pentagonal number as these numbers can be used as points to form a pentagon. For example, some of pentagonal numbers are 1, 5, 12, 22, 35, 51....We can use formula to check whether the number is a pentagonal number or not$$p(n)=\frac{\text{3}*n^2-n}{\text{2}}$$Where, n is the number of points pentagonal will haveExampleInput-: n=22 Output-: 22 is pentagonal number Input-: n=23 Output-: 23 is not a pentagonal numberAlgorithmStart Step 1 -> declare function ... Read More
If input is in km/hr convert it to miles/hr else input will be in miles/hr convert it to km/hr. There are formulas that can be used for this conversion.Conversion Formulas −1 kilo-metre = 0.621371 miles 1 miles = 1.60934 Kilo-meterExampleInput-: kmph= 50.00 Mph = 10.00 Output-: speed in m/ph is 31.07 speed in km/ph is 16.0934AlgorithmStart Step 1 -> Declare function to convert km/ph to m/ph double km_mph(double km) return 0.6214 * km step 2 -> Declare function to convert m/ph to km/ph double m_km(double m_ph) return m_ph * 1.60934 ... Read More
Given with hexadecimal number as an input, the task is to convert that hexadecimal number into a binary number.Hexadecimal number in computers is represented with base 16 and binary number is represented with base 2 as it has only two binary digits 0 and 1 whereas hexadecimal number have digits starting from 0 – 15 in which 10 is represented as A, 11 as B, 12 as C, 13 as D, 14 as E and 15 as F.To convert hexadecimal number into binary number every number is converted into its binary equivalent of 4 bits and after that these numbers ... Read More
Conversion Formulas −1 km/hr = 5/18 m/sec or 0.277778 m/sec 1 m/sec = 18/5 km/hr or 3.6 km/hrExampleInput-: km = 60.00 mk = 70.00 Output-: speed in meter per second = 16.6667 speed in km per hour = 252AlgorithmStart Step 1 -> Declare function to convert km/hr into m/sec float km_m(float km) return (0.277778 * km) Step 2 -> Declare function to convert m/sec into km/hr float m_km(float mk) return (3.6 * mk) step 3 -> In main() declare variable as float km = 60.0 and float mk = ... Read More
If input is in radian convert it to degree else input will be in radian convert it to degree. There are formulas that can be used for this conversion.Radian is the standard unit for measuring angles whereas the complete angle of circle is divided into 360 degree. Also, radian is the smaller value as 1 degree = 180 radians.Conversion Formulas −degree = radian * (180/pi) where, pi=3.14 or 22/7ExampleInput-: radian = 9.0 Output-: degree is : 515.92357AlgorithmStart Step 1 -> define macro as #define pi 3.14 Step 2 -> declare function for converting radian to degree double convert(double radian) ... Read More
Given two matrix M1[r][c] and M2[r][c] with ‘r’ number of rows and ‘c’ number of columns, we have to check that the both given matrices are identical or not. If they are identical then print “Matrices are identical” else print “Matrices are not identical”Identical MatrixTwo matrices M1 and M2 are be called identical when −Number of rows and columns of both matrices are same.The values of M1[i][j] are equal to M2[i][j].Like in the given figure below both matrices m1 and m2 of 3x3 are identical −$$M1[3][3]=\begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \ 7 & ... Read More
Problem statementGiven two numbers n and k, we need to find the minimum number of flips required to maximize given number by flipping its bits such that the resulting number has exactly k set bits. Please note input must satify condition that k < number of bits in n.ExampleLet us suppose n = 9 and k = 2Binary representation of 9 is − 1001. It contains 4 bits.Largest 4 digit binary number with 2 set bits is − 1100 i.e. 12To convert 1001 to 1100 we have to flip highlighed 2 bitsAlgorithm1. Count the number of bits in n. Let ... Read More
Problem statementGiven three arrays with 0’s and 1’s of size n, the task is to find minimum flip of bits in the first and second array such that the XOR of i’th index bit of first and second array is equal to i’th index bit of the third array.Please note that we can only flip at most p bits of array 1 and at most q bits of array 2. Also rearranging array elements is not allowed.Let us suppose p = 2 and q = 5arr1[] = {1, 0, 1, 1, 0, 1, 0} arr2[] = {0, 1, 0, 1, ... Read More
In linear algebra a matrix M[][] is said to be a symmetric matrix if and only if transpose of the matrix is equal to the matrix itself. A transpose of a matrix is when we flip the matrix over its diagonal, which resultant switches its row and columns indices of the matrix.Below the example of Symmetric matrix −$$\begin{bmatrix} 1 & 4 & 7 \ 4 & 5 & 6 \ 7 & 6 & 9 \ \end {bmatrix} \Rightarrow \begin{bmatrix} 1 & 4 & 7 \ 4 & 5 & 6 \ 7 & 6 & 9 \ \end{bmatrix}$$The above ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP