For a class I am taking, I have to write a program that looks at the out come of a coin toss for 1000, 10000, and 100000 tosses. I am also required to keep count of the longest sequence of heads or 1's and the longest sequence of alternating head and tails 1010101. heads = 1 tails = 0.
i am having trouble with the latter, I need help on keeping track of the sequences. Here is my code so far:
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, heads = 0, tails = 0, x;
for(i = 1; i < 1000; i++){
x = rand() % 2;
if(x == 1)
heads++;
if(x == 0)
tails++;
}
printf("%d heads, %d tails\n", heads, tails);
return 0;
}