SVN / public / code / vorlesung-02 / BirthdayParadoxMain.cpp

Revision 11340
Date
Committerhb1003
Download
// Copyright 2016, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Hannah Bast <bast@cs.uni-freiburg.de>.

// Include some functions from elsewhere: stdio (standard input/output) contains
// printf, stdlib (standard library) contains exit and atoi. More about
// libraries in lecture 2.
#include <stdio.h>
#include <stdlib.h>

// Include declarations from header files.
#include "./BirthdayParadox.h"

// #include "./BirthdayParadox.cpp"
// Declare the function (it is implemented elsewhere).
// int probabilitySameBirthday(int n);

// Main function, argc is the number of command line arguments and argv is an
// array of pointers to these arguments; this will be explained in a later
// lecture.
int main(int argc, char** argv) {
  // printf("Number of command line arguments: %d\n", argc);
  if (argc != 2) {
    printf("Usage: ./BirthdayParadox <number of people>\n");
    exit(1);
  }
  int n = atoi(argv[1]);

  printf("Number of people: %d\n", n);
  double p = probabilitySameBirthday(n);
  printf("Probability that at least two have the same birthday: %.1f%%\n",
      100 * p);
}