[ Note: Each side of the coin appear approximately half the time for a total of approximately 50 heads and 50 tails. ]
/*
title: tossingCoin
author: aeriqusyairi
date: Jan24 2012
*/
#include<stdio.h>
#include<stdlib.h>
int flip(void);
int main(){
int countHead = 0, countTail = 0, i, x;
for(i = 0; i < 100; i++){
x = flip();
if(x == 1){
printf("Heads\n");
countHead++;
}else if(x == 0){
printf("Tails\n");
countTail++;
}
}
printf("TOTAL HEAD: %d\nTOTAL TAIL: %d\n", countHead, countTail);
system("pause");
return 0;
}
int flip(void){
return rand() % 2;
}
No comments:
Post a Comment