giovedì 24 settembre 2009

Uso della funzione rand() nel linguaggio C

#include

main ()
{
int segreto, ipotesi;

/* initialize random seed: */
srand ( time(NULL) );

/* genera il numero segreto: */
segreto= rand() % 10 + 1;

do {
printf ("indovina un numero (1 to 10): ");
scanf ("%d",&ipotesi);
if (segreto else if (segreto>ipotesi) puts ("Il numero segreto è più grande");
} while (segreto!=ipotesi);

puts ("congratulazioni!");

}