Found 7197 Articles for C++

C++ Program for triangular pattern (mirror image around 0)

Sunidhi Bansal
Updated on 09-Jul-2020 08:23:06

335 Views

Given with the positive value n and the task is to generate the triangular pattern i.e. mirror image of the printed numbers and display the resultExampleInput-: n = 6 Output-:Input-: n = 3 Output-:Approach used in the below program is as follows −Input the value of n as a positive integerTraverse one loop i for the number of rows in a pattern i.e. nTraverse one loop j for the number of spaces in a patternTraverse another loop for the digits in a patternAlgorithmSTART Step 1-> declare function to print mirror image of triangular pattern    void print_mirror(int n)    declare ... Read More

C++ Program for converting hours into minutes and seconds

Sunidhi Bansal
Updated on 09-Jul-2020 08:23:37

1K+ Views

Given with the input as hours and the task is to convert the number of hours into minutes and seconds and display the corresponding resultFormula used for converting the hours into minutes and seconds is −1 hour = 60 minutes    Minutes = hours * 60 1 hour = 3600 seconds    Seconds = hours * 3600ExampleInput-: hours = 3 Output-: 3 hours in minutes are 180    3 hours in seconds are 10800 Input-: hours = 5 Output-: 5 hours in minutes are 300    5 hours in seconds are 18000Approach used in the below program is as follows ... Read More

C++ Program to calculate the value of sin(x) and cos(x)

Sunidhi Bansal
Updated on 20-Nov-2019 13:07:30

5K+ Views

Given with the input as angles and the task is to calculate the value of sin(x) and cos(x) corresponding to the given angle and display the resultFor Sin(x)Sin(x) is a trigonometric function which is used to calculate the value of x angle.Formula$$\sin (x) = \displaystyle\sum\limits_{k=0}^\infty \frac{(-1)^{k}}{(2k+1)!}x^{2k+1}$$For Cos(x)Cos(x) is a trigonometric function which is used to calculate the value of x angle.Formula$$\cos (x) = \displaystyle\sum\limits_{k=0}^\infty \frac{(-1)^{k}}{(2k)!}x^{2k}$$Approach used in the below program is as follows −Input the value of x angle for sin(x) and cos(x)Apply the formulas given for sin(x) and cos(x)Print the resultALGORITHMSTART Step 1-> declare function to calculate value of ... Read More

C++ Program to compute division upto n decimal places

Sunidhi Bansal
Updated on 20-Nov-2019 12:59:42

1K+ Views

Given with the value of x and y as a positive integer with the value of n for number of decimal places and the task is to generate the division up to n decimal places.ExampleInput-: x = 36, y = 7, n = 5 Output-: 5.14285 Input-: x = 22, y = 7, n = 10 Output-: 3.1428571428Approach used in the below program is as follows −Input the value of a, b and nCheck if b is 0 than division will go upto infinite and if a is 0 than result will be 0 as something divides to 0 is ... Read More

C++ Program to check whether points in a 3-D plane are Coplanar

Sunidhi Bansal
Updated on 20-Nov-2019 12:54:39

467 Views

Given with the points (x1, y1, z1), (x2, y2, z2), (x3, y3, z3) and (x4, y4, z4) and the program must check whether the given points are coplanar or not. Points are said to be coplanar is they lie under same plane and if they are under different-2 planes than the points are not coplanar.Given below is an image containing four points and all are under same plane which is xy plane that means points are coplanarGiven below is an image containing four points and all are under different planes which shows points are not coplanarExampleInput-: x1 = 2, y1 ... Read More

C++ Program to check if a given number is Lucky (all digits are different)

Sunidhi Bansal
Updated on 20-Nov-2019 12:48:18

947 Views

Given with a number and the task is to check whether the input number is a lucky number or not and display the result.What is a Lucky NumberLucky number is the number whose each and every digit is different and if at least one digit is repeating than the number will not be considered as a lucky number.ExampleInput-: n = 1234 Output-: it is a lucky number Explanation-: As there is no repeating digit in a number n so it is a lucky number Input-: n = 3434 Output-: it is not a lucky number Explanation-: In the given number ... Read More

C++ Program to calculate the profit sharing ratio

Sunidhi Bansal
Updated on 20-Nov-2019 12:44:56

497 Views

Given with an array of amount invested by multiple person and another array containing the time period for which money is invested by corresponding person and the task is to generate the profit sharing ratio.What is Profit Sharing RatioIn a partnership firm, profits and losses are shared between the partners depending upon the capital invested by them in the business. On the basis of that capital investment percentage we calculate the profit sharing ratio which shows the amount of profit which is to be given to each partner of a business.Formula − Partner 1 = capital invested * time period ... Read More

C++ Program to calculate the number of odd days in given number of years

Sunidhi Bansal
Updated on 20-Nov-2019 12:34:50

239 Views

Given with the positive integer value n and the task is to generate the number of odd days till the given year n.ExampleInput-: days = 500 Output-: number of odd days are: 5 Input-: days = 400 Output-: number of odd days are: 0How to calculate the number of odd days in given number of yearsFor calculating the number of odd days the first thing we need to check is whether the given year is a leap year or not because if it’s a leap year than the number of odd days will get changed. If the year is divisible ... Read More

C++ Program to calculate Double Integration

Sunidhi Bansal
Updated on 20-Nov-2019 12:32:21

2K+ Views

We are given with the lower limit of variable x, upper limit of variable x, lower limit of variable y, upper limit of variable y, steps taken for corresponding x and steps taken for corresponding y and the task is to generate the double integration and display the result.ExampleInput-: steps for x = 1.2 steps for y = 0.54 lower limit of x = 1.3 upper limit of x = 2.1 lower limit of y = 1.0 upper limit for y = 2.1 Output-: double integration is : 2.1Approach used in the below program is as follows −Input the value ... Read More

C++ Program Probability for three randomly chosen numbers to be in AP

Sunidhi Bansal
Updated on 20-Nov-2019 12:24:58

207 Views

Given with an array of numbers ‘n’ and the task is to find the probability of three randomly chosen numbers to be in AP.ExampleInput-: arr[] = { 2, 3, 4, 7, 1, 2, 3 } Output-: Probability of three random numbers being in A.P is: 0.107692 Input-:arr[] = { 1, 2, 3, 4, 5 } Output-: Probability of three random numbers being in A.P is: 0.151515Approach used in the below program is as follows −Input the array of positive integersCalculate the size of the arrayApply the formula given below to find the probability of three random numbers to be in ... Read More

Advertisements