Concept explainers
To write the similar program for previous exercise in another language than BASIC.
Explanation of Solution
Given:
Break a stick into three pieces to get the probability that you can join the pieces end-to-end to form a triangle. If the sum of the length of any two pieces is less than or equal to that of the third, a triangle can’t be form. This is known as Triangle Inequality. By an experiment your class can estimate the probability that three pieces of broken stick will form a triangle.
Calculation:
Let D, N, I, X, Y, R, S and T variables used in program. Where D stands for number of sticks you have to break, N stands for first end of stick that is 0, I stands for variable of for loop assign from 1 to D, X and Y are stand for the length of points distance from initial point that is 0, R assigned as X, S assigned as Y − R and T assigned for 1 − R − S. Consider the program below-
The given program in C programming language is
Program:
#include <stdio.h> #include <math.h> #include <conio.h> int main(int argc, char *argv[]) { int D=0; int N=0; int I=1; float X=0, Y=0, R, S, T, P; printf("SIMULATION--BREAKING STICKS TO MAKE TRIANGL...*I); do { // get the random number between 0 and 1; line 70, 80 X = ((float)(rand()%100))/(float)100; Y = ((float)(rand()%100))/(float)100; } while (X>=Y); // if condition for X>=Y // for lines 100-150 R = X; S = Y-R; T = 1-R-S; if (R+S <= T) continue; if (S+T <= R) continue; if (R+T <= S) continue; N = N+1; } P = (float)N/(float)D; printf("\nTHE EXPERIMENTAL PROBABILITY THAT\nA BROKEN STICK CAN FORM A TRIANGLE IS %f\n",P); return 0; }
Sample Output:
SIMULATION--BREAKING STICKS TO MAKE
HOW MANY STICKS DO YOU WANT TO BREAK:100
THE EXPERIMENTAL PROBABILITY THAT
A BROKEN STICK CAN FORM A TRIANGLE IS 0.260000
Output Explanation:
SIMULATION--BREAKING STICKS TO MAKE TRIANGLES
Enter number of sticks as 10 which you want to break that is value of variable D
HOW MANY STICKS DO YOU WANT TO BREAK:100
THE EXPERIMENTAL PROBABILITY THAT
Then you get the experimental probability equal to 0.260000 that is P=0.260000
A BROKEN STICK CAN FORM A TRIANGLE IS 0.260000
Chapter 6 Solutions
McDougal Littell Jurgensen Geometry: Student Edition Geometry
Additional Math Textbook Solutions
Calculus: Early Transcendentals (2nd Edition)
Algebra and Trigonometry (6th Edition)
Pre-Algebra Student Edition
Elementary Statistics
University Calculus: Early Transcendentals (4th Edition)
Basic Business Statistics, Student Value Edition
- Elementary Geometry For College Students, 7eGeometryISBN:9781337614085Author:Alexander, Daniel C.; Koeberlein, Geralyn M.Publisher:Cengage,Elementary Geometry for College StudentsGeometryISBN:9781285195698Author:Daniel C. Alexander, Geralyn M. KoeberleinPublisher:Cengage Learning