Hello,
I am experimenting with random numbers and guessing games, this is my attempt.
It works for me, can someone give some better solution to the program?
Thanks in advance.
FSX
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int randno, guess, test, count, high, low; randno = guess = test = count = high = low = 0; { time_t t = time(NULL); while (t > 0u - 1 + 0.0) t = t / 2; srand(t); printf("Il random seed e' %d\n", t); } randno = (rand()%100000)+1; printf("Il numero da indovinare e': %d\n", randno); count = 1; high = 100000; low = 0; test = (high+low)/2; printf("Il numero provato e' %d.\n", test); while(test != randno) { if(test > randno) high = test; else low = test; test = (high+low)/2; printf("Il numero provato e' %d.\n", test); } return 0; }



LinkBack URL
About LinkBacks



