Rolling a Six-Sided Die
Welcome to C programming tutorial, we will be writing a program illustration that Rolls a Six-Sided.
A fair die means that each of the faces has the same probability of landing facing up; A standard six-sided die, for example, can be considered "fair" if each of the faces has a probability of 1/6.
The Program will be required to loop 20 times and on each loop the rand() function for number generation will be called to be picking numbers randomly between 1 to 6.
A fair die means that each of the faces has the same probability of landing facing up; A standard six-sided die, for example, can be considered "fair" if each of the faces has a probability of 1/6.
The Program will be required to loop 20 times and on each loop the rand() function for number generation will be called to be picking numbers randomly between 1 to 6.
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int i;
for(i=1; i<=20; i++){
printf("%5d", 1+(rand()%6));
if(i%5==0){
printf("\n");
}
}
return 0;
}
Comments
Post a Comment
Please feel free to comments if you have any ideas, questions and subjection concerning our post and programs