This blog is under construction

Tuesday 9 July 2013

C program to guess a random number

C program to guess a random number.


  #include <stdio.h>
  #include <stdlib.h>

  int main() {
        int num, guess;

        /* generate a random number using rand() API */
        num = rand();

        /* get the number user guesses */
        printf("Guess the random number:");
        scanf("%d", &guess);

        /* print the results */
        if (guess == num) {
                printf("Excellent!! Guessed correctly!!!\n");
        } else {
                printf("Wrong Guess!!\n");
        }
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Guess the random number:233255
  Wrong Guess!!





See Also:

No comments:

Post a Comment