Block of Code

Practical Examples for Programmers

  • Home
  • C++
  • Java
  • Visual Basic
  • Discrete Math
  • Ask a Question

Birthday Problem

Given a random group of 23 people, how likely is it that two people have the same birthday?  To answer this question, write a program that creates an array of 23 elements, randomly assigns to each subscripted variable one of the integers from 1 through 365, and checks to see if any of the subscripted variables have the same value.  (Make the simplifying assumption that no birthdays occur on February 29.)  Now expand the program to repeat the process 1000 times and determine the percentage of the time that there is a match.  See the figure below for an example of what this might look like.

Birthday Problem Screenshot
Suggested Control Names and Attributes( without container ):

Name Property Text Property Control Type Notes
 frmBirthdays Birthdays Form Holds Controls
 btnCompute Compute Birthday Probability Button Triggers event to calculate and display results
 txtMatches TextBox Displays probability.  Read Only property set to True.

Secondary Sidebar

This is the secondary sidebar

Copyright © 2025 · Metro Pro Theme on Genesis Framework · WordPress · Log in