Thursday, 20 March 2014

program in c to show the “randomization of die-roll”

/*…… hey guy’s it is a randomizing die rolling program…*/
#include <stdlib.h>
#include<conio.h>
#include <stdio.h>
/*…Main function start’s….*/
void main()
{
/*….Initialization…*/
int i;
unsigned seed;
printf( “Enter seed: ” );
scanf( “%u”, &seed );
srand( seed );        //here srand is used to randomise the seed…….
/*….Loop start’s…*/
for ( i = 1; i <= 10; i++ ) 
{
printf( “%10d”, 1 + ( rand() % 6 ) );
/*…Condition checking..*/
if ( i % 5 == 0 )
printf( “\n” );
}
/*….Loop end’s….*/
getch();
}
/*…Main function end’s..*/

Image

No comments:

Post a Comment