[ create a new paste ] login | about

Link: http://codepad.org/qPcSo6P9    [ raw code | output | fork ]

C, pasted on Feb 15:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <stdlib.h>

int main(void){

int randnum;
int numruns = 10000;
int num42 = 0;
int i;
for(i = 0; i<numruns; i++){
randnum = rand()%100;
if (randnum == 42){num42 += 1;}
}
printf("got 'forty-two' %d times out of %d which is %f percent", num42, numruns, (float)num42/numruns*100);
return 0;
}


Output:
1
got 'forty-two' 107 times out of 10000 which is 1.070000 percent


Create a new paste based on this one


Comments: