Guess a random number with if...else statement - C Data Type

C examples for Data Type:Random Number

Description

Guess a random number with if...else statement

Demo Code

#include <stdio.h>

#include <stdlib.h>
int main(void)
{
   int magic; /* magic number */
   int guess; /* user's guess */

   magic = rand(); /* generate the magic number */

   printf("Guess the magic number: ");
   scanf("%d", &guess);

   if (guess == magic) printf("** Right **");
   else printf("Wrong");

   return 0;//from   w  ww.  j  a  v  a  2s  . c  om
}

Result


Related Tutorials