A simple program in c which the program choose one random number from 1-500 and the user has to guess that number. The program notifies user if his guess is too low or too hight and counts all the user tries.
#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int magic, guess, counter; srand(time(NULL)); magic=(rand()%500)+1; counter=0; do { printf ("Make Your Guess: "); scanf ( "%d" , &guess); counter++; if ( guess==magic ) { printf ( "You have found it after %d trial(s) , " , counter); printf ( "%d is the number ! \n" , magic ); } else { printf ( "Wrong number , You are "); if ( guess > magic) printf ("Too high... "); else printf ("Too low... "); printf ( "You have made %d trial(s) \n" , counter); } }while (guess!=magic); system("PAUSE"); return 0; }
Feed for this Entry Trackback Address The permalink
Be the first to comment this entry.


Recent Comments