Same birthday

Assignment Help C/C++ Programming
Reference no: EM13165703

How likely is it that two people in one section of our class (40 students) have the same birthday ?

Suggested Approach:

  1. Prepare an integer array, a[40], to hold birthdays for 40 students.
  2. Generate a random number between 1 and 365 and assign the number to each element of a[]. Use the % operator (Example: 300%7 returns the remainder of 300 divided by 7).
  3. Compare a[0] with the rest of the students' birthdays (i.e. a[1], a[2], ..... a[22]) and if there is a match, get out of the loop, increment the counter by 1 and go to #2 (the next round of simulation).
  4. Compare a[1] with the rest of the students' birthdays (i.e. a[2], a[3], ..... a[22]) and if there is a match, get out of the loop, increment the counter by 1 and go to #2 (the next round of simulation).
  5. Compare a[2] with the rest of the students' birthdays (i.e. a[3], a[4], ..... a[22]) and if there is a match, get out of the loop, increment the counter by 1 and go to #2 (the next round of simulation).
  6. Compare a[3] with the rest of the students' birthdays (i.e. a[4], a[5], ..... a[22]) and if there is a match, get out of the loop, increment the counter by 1 and go to #2 (the next round of simulation).
  7. ¼.
  8. After n simulations, compute the value of counter/n.

Example of goto statement (to get out of the loop):

for (i=0;i<N-1;i++) for (j=i+1;j<N;j++)

   if(birthday[i]==birthday[j])

          {count++;goto ExitLoop;}

 

ExitLoop:;

.....

 

 

Reference no: EM13165703

Questions Cloud

Reason why you would not install cables : Give me two reason why you would not install cables in ducts that are used to transport dust loos stock, flammable vapors or in those ducts that are used for ventilattion for cooking?
State what is the concerntration of the weak acid : The student then titrated 25.0 ml of the same buffer with 0.1115 M NaOH. The observed titration curve is shown below
Write a c function that converts a character to upper case. : Write a C function that converts a character to upper case. The function should have the prototype char to_upper(char ch); The characters given as input to the function are assumed to be in the sets {'a', ..., 'z'} and {'A', ... , 'Z' }. Do not use a..
Network engineer for abc company : You are the network engineer for ABC company. Business is booming, a lot of new staff has been hired recently, and the company is running out of office space. A new larger building has been purchased and you have been asked to design the network f..
Same birthday : How likely is it that two people in one section of our class (40 students) have the same birthday ?
Sense the language of a : For this, sense the language of A is in the set of all languages, would showing this just involve making a DFA of one state that accepts everything? I am not sure how to show this.
State what is the standard potential of the cell : Write the cell reaction that occurs if the two Pt electrodes are shorted together. What is the standard potential of the cell?
Write a java program that prints the numbers from 1 to 125 : Write a Java Program that prints the numbers from 1 to 125. But for multiles of three print "Batman" instead of the number and for the multiples of five print "Superman". For instances which are multiples of both three and five "JusticeLeague".
State degree celcius in an adiabatic calorimeter : What must be the initial temperature of 22g of steam that is mixed with 90g of water at 68 degree celcius in an adiabatic calorimeter with a heat capacity of zero and that produces

Reviews

Write a Review

C/C++ Programming Questions & Answers

  . write a segment of code that prints the number of elements

Assuming the array x has been defined as: int x[n]; for some n and that values have been assigned to all the elements. Write a segment of code that prints the number of elements between (but not including) the largest and smallest values in the array..

  Create class has three pieces of information as data members

Create a class called Date in C++ that includes three pieces of information as data members: month (type int), day (type int) and yaer (type int).

  Containing all the genes in the dna sequence

As described above plus an integer reference parameter, and return a dynamically-allocated array of strings containing all the genes in the DNA sequence. Each string in the array will contain a unique

  Iterative programming problem solving approaches

Write a recursive function void reverse ( ) that reverse a sentence

  Design a deck plan space ship in eclipse

Develop a simple interactive two-dimensional spaceship deck plan editor using OpenGL and GLUT. Your program will enable a user to create and save a deck plan of a hypothetical spaceship comprising the hull walls.

  Prepare a linux shell

Prepare a linux shell (in other words, write a C/C++ program) that will recursively prompt for input from the user. The shell should prompt as

  Reverses the characters in a character array

Write the function reverseit that reverses the characters in a character array. You must also write main that calls reverseit.

  Asks the user for the name of an input file and translates

Write a C++ program that asks the user for the name of an input file and translates the contents of that input file using ROT13. Your  main  function should be responsible for reading the input file and coordinating calls to a value-returning functio..

  Create an employee class

Create an employee class, including two data: an employee number (type int ) and the employee's compensation (in dollars; type float). The member data should comprise an int for storing the employee number and a float for storing the employee's co..

  Write a method, to be included in a template unsorted list

Write a metho, to be included in a template unsorted list class, called replace_item, that will receive two xType parameters, one called olditem, the other called newitem.

  You will write a program that reads a text file

You will write a program that reads a text file, counts the number of words in the file, and the number of occurrences of each character. It will print to a file the number of words, and the number of occurrences of each character, as well as the ..

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd