Before being introduced to probability, you need to be familiar with Sample Spaces and the Algebra of sets. Sample Spaces is referred to the potential outcomes of an event. To understand better, consider the following examples:
What is the sample space of the experiment of flipping a coin 3 times?
Basically you are going to flip a coin three times and record outcome of each toss and the ordered triples would be your sample outcome.
Sample Space, S, = {HHH, HHT, HTH, THH, HTT, THT, TTH, TTT}.
What is the sample space for choosing an even number from 0 to 10 at random?
S = {2, 4, 6, 8, 10}.
In C Plus Plus, C Sharp, Java, PHP, Algorithms, Computer Science and more.... By Gurpreet Singh
Showing posts with label Math. Show all posts
Showing posts with label Math. Show all posts
Tuesday, June 18, 2013
Tuesday, June 11, 2013
C++ Program to Calculate Factorial
The factorial of n is the product of all positive integers up to and including N. N! = 1 * 2 *3.. * N. For this program you need to know your data types size and range. Refer to CPlusPlus.com for table that displays size and range of many data types. If you define your variables to be integer data type (integer range is from -2147483648 to 2147483647), the program will give you wrong answer because you will fall out of the range after 13 factorial. You will only get the right answer for the first 12 numbers. To avoid getting wrong answers, you can user double or long double which is basically the same thing which can take up to 15 digits in range.
C Plus Plus Program to Calculate Factorial
C Plus Plus Program to Calculate Factorial
C++ Program for Euclid's GCD Algorithm
Euclidean Algorithm is an efficient method of finding the greatest common divisor. It was named after a Greek mathematician Euclid. The Algorithm begins with two positive integers A and B then replaced by X and Y. Then while Y is not zero, at each step X is replaced by Y and then Y is replaced by X mod Y (remainder of a divided by b). The algorithm halts when B = 0.
Pseudo Code for Euclid's GCD Algorithm
Procedure GCD(A, B: positive integers)
X := A
Y := B
while Y != 0
R := X mod Y
X := Y
Y := R
return X {GCD(a,b) is X}
C Plus Plus Program for Euclid's GCD Algorithm
Pseudo Code for Euclid's GCD Algorithm
Procedure GCD(A, B: positive integers)
X := A
Y := B
while Y != 0
R := X mod Y
X := Y
Y := R
return X {GCD(a,b) is X}
C Plus Plus Program for Euclid's GCD Algorithm
C++ Program to Convert Rectangular to Polar Coordinates
To start with this program you must understand definitions of Rectangular and Polar coordinates. Rectangular coordinates are x and y position on a Cartesian coordinate system. To calculate Polar coordinates from Rectangular coordinates you have the calculate the distance from the Origin, r, and the angle from the x-axis, θ, specified by the point. To Understand better, I have drawn an image:
We need to know x and y on a Cartesian coordinate system to calculate the Polar coordinates, r and θ. We can use the following formulas:
r = √ (x^2 + y^2)
θ = arctan (y/x) where x != 0
C Plus Plus Program to Convert Rectangular to Polar Coordinates
r = √ (x^2 + y^2)
θ = arctan (y/x) where x != 0
C Plus Plus Program to Convert Rectangular to Polar Coordinates
Monday, June 10, 2013
C++ Program to Solve the Quadratic Equation
Welcome to GSinghCodes. This is the first post on this Blog, hopefully I will continue to add more as time progresses.
Today I will explain the C Plus Plus Program which Solves the Quadratic Equation. Before we get started we need to look at the Quadratic Equations. "Standard Form" of a Quadratic Equation is ax2 + bx + c = 0, where a b and c are known, a cannot be zero and x is the unknown variable we have to find. To solve the equation we can use the quadratic formula:
Their are three types of answers you can get with the quadratic formula, Two real solutions (If the discriminant (the part inside the square root) is greater than zero) , No Real Solution (If the discriminant is strictly less than zero and One real solution(If the discriminant is equal to zero). To See Examples Click Here.
Examples To Test
0x^2 + 0x + 0 = 0 Answer = "All Solutions"
0x^2 + 0x + 1 = 0 Answer = "No Solutions"
0x^2 + 2x + 1 = 0 Answer = -1/2
1x^2 + 2x + 1 = 0 Answer = "Duplicate Solution" = -1
1x^2 + 4x + 1 = 0 Answer = "two solutions" = d = 3.464 1st root = -0.267 | 2nd root = -3.73
C Plus Plus Program to Solve the Quadratic Equation
Today I will explain the C Plus Plus Program which Solves the Quadratic Equation. Before we get started we need to look at the Quadratic Equations. "Standard Form" of a Quadratic Equation is ax2 + bx + c = 0, where a b and c are known, a cannot be zero and x is the unknown variable we have to find. To solve the equation we can use the quadratic formula:
Their are three types of answers you can get with the quadratic formula, Two real solutions (If the discriminant (the part inside the square root) is greater than zero) , No Real Solution (If the discriminant is strictly less than zero and One real solution(If the discriminant is equal to zero). To See Examples Click Here.
Examples To Test
0x^2 + 0x + 0 = 0 Answer = "All Solutions"
0x^2 + 0x + 1 = 0 Answer = "No Solutions"
0x^2 + 2x + 1 = 0 Answer = -1/2
1x^2 + 2x + 1 = 0 Answer = "Duplicate Solution" = -1
1x^2 + 4x + 1 = 0 Answer = "two solutions" = d = 3.464 1st root = -0.267 | 2nd root = -3.73
C Plus Plus Program to Solve the Quadratic Equation
Subscribe to:
Posts (Atom)
