C program

timer Asked: Jan 1st, 2018
account_balance_wallet $15

Question description

please see the attachment in order to know what are the requirements. you should work on the C program, all what you have to do is to type the requirements in the C program , they are really easy

ECE 102 Assignment #20 Monte Carlo method to estimate pi Review the notes for the description of this problem. Write a C program to implement the pseudocode as written. Add appropriate comments. Analysis: Input: the total number of darts (N, integer) Output: an estimate of pi (pi_estimate, double) Formula: pi_estimate = 4.0 *M / N, where M is the number of darts that fall within the unit circle constraint: N should be a large integer N > 500 intermediate variables: the number of darts inside the circle (M, integer) counter for the number of darts thrown (counter, integer) the position (coordinates) of a dart (x, y, double) Programming note: x =2* rand – 1; %randomly generate x coordinate between -1 and 1 y =2*rand – 1; %randomly generate y coordinate between -1 and 1 Pseudocode: 1. Get user input for the total number of darts, N 2. Error checking for N to be a large number N > 500 while (1) if N is less than or equal to 500 Display “error> N must be greater than 500” Get input for N else break; 3. Use a while loop to simulate the dart throwing and counting. a. Initialize the initial count to M = 0. M is the number of darts within the circle. b. Initialize the counter = 0 c. while counter is less than N Simulate throwing a dart (x=2*rand -1; y=2*rand -1;) //the location of the dart is (x, y) if (x, y) is within the circle (math relation: x2 + y2 <= 1) increment M by 1 4. Compute an estimate for pi: pi_estimate= 4.0*M/ N 5. Display the output: An estimate for pi is ___________ about _______ darts are thrown in this Monte pi_estimate N Carlo experiment
ECE 102 Assignment #21 Write a program that simulates the play of the game of pig. We will discuss this problem again on Wednesday, 11/15. Prelab: 1. Write down a detailed pseudocode. Hint: another running sum is needed to in order to get the total score for the entire game. Review the notes on how to calculate a running sum. 2. Trace the pseudocode to make sure the total score is calculated correctly. 3. Try your best to fix the pseudocode to make sure that it works correctly before writing the program. 4. Embed the while loop in your program for Assignment #19 in this assignment for the play of each turn.

Tutor Answer

School: UIUC

#20 and #21. That should be all the code; do you still want the writeup for all the questions?

Ali Almusallam
This program simulates the game of pig for 5 turns*/
#define ddie 6 /* number of faces on die */
#define turns 5 /* number of turns in a game of pig*/
int main(void)
int score = 0; /* player's total score*/

flag Report DMCA

Wow this is really good.... didn't expect it. Sweet!!!!

Similar Questions
Hot Questions
Related Tags

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors