Skip to content

Instantly share code, notes, and snippets.

@tanerochris
Last active August 29, 2015 14:17
Show Gist options
  • Save tanerochris/e6ae0b6ef4835542db93 to your computer and use it in GitHub Desktop.
Save tanerochris/e6ae0b6ef4835542db93 to your computer and use it in GitHub Desktop.
A program to simulate the tossing of a coin
#include<stdio.h>
//a program to simulate the tossing of a coin
int flip();
int flip(){
return random()%2;
}
int main(void){
int i,h=0,t=0;
srand(time(NULL));
for(i=0;i<100;i++){
if(flip())
{
printf("HEAD\n");
h=h+1;
}
else{
printf("TAIL\n");
t=t+1;
}
}
printf("tails=%d head=%d",t,h);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment