C++ Program for Area of Square After N-th Fold

Sunidhi Bansal
Updated on 23-Sep-2019 11:50:02

184 Views

Given a side of a square and the number of fold, we have to find the Area of square after number of folds.A square is a 2-D shape like rectangle where all the sides are equal. And it’s all angles are equal to 90 degrees.While folding a square we −Fold the square from top left side of the triangle to the bottom of the right side forming a triangle.The second fold will be folding from up to downside.The third fold is folding again from left to right.And likewise we follow the above steps.ExamplesInput: side = 23, fold = 4 Output: ... Read More

C Program for Area and Perimeter of Rectangle

Sunidhi Bansal
Updated on 23-Sep-2019 11:47:18

3K+ Views

Given a length and breadth of a rectangle we have to find its area and Perimeter.Rectangle is 2-D figure containing four sides and four angles of 90 degree each. All the sides of rectangle are not equal only the opposite sides of a rectangle are equal. The diagonals in a rectangle also are of the same length.Below is a diagrammatic representation of rectangle.Here A represents the breadth and B represents length of the rectangle.To find the Area of a rectangle the formula is: Length x BreadthAnd Perimeter of a rectangle is − 2 x (Length+Breadth).ExamplesInput: 20 30 Output: area of rectangle ... Read More

C Program for N-th Odd Number

Sunidhi Bansal
Updated on 23-Sep-2019 11:46:16

994 Views

Given a number N we have to find the N-th odd number.Odd numbers are the numbers which are not completely divided by 2 and their remainder is not zero. Like 1, 3, 5, 7, 9, ….If we closely observe the list of even numbers we can also represent them as(2*1)-1=1, (2*2)-1=3, ( 2*3)-1=5, (2*4)-1=7, ….(2*N)-1.So, to solve the problem we can simply multiply the number N with 2 and subtract 1 from the result, that makes up an odd number.ExamplesInput: 4 Output: 7 The 4th odd number is 1, 3, 5, 7.. Input: 10 Output: 19AlgorithmSTART    STEP 1 -> ... Read More

C Program for N-th Even Number

Sunidhi Bansal
Updated on 23-Sep-2019 11:39:33

659 Views

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

Check if N is a Pentagonal Number in C++

Sunidhi Bansal
Updated on 23-Sep-2019 11:37:11

568 Views

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

Convert km/hr to miles/hr and Vice Versa in C++

Sunidhi Bansal
Updated on 23-Sep-2019 11:12:51

607 Views

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

Convert Hexadecimal Number to Binary in C++

Sunidhi Bansal
Updated on 23-Sep-2019 11:10:09

1K+ Views

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

Convert Speed in Km/hr to m/sec and Vice Versa in C++

Sunidhi Bansal
Updated on 23-Sep-2019 11:00:19

778 Views

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

Convert Radian to Degree in C

Sunidhi Bansal
Updated on 23-Sep-2019 10:58:09

2K+ Views

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

Check If Two Matrices Are Identical in C++

Sunidhi Bansal
Updated on 23-Sep-2019 10:55:03

1K+ Views

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

Advertisements