Guess a random number with the ? operator - C Operator

C examples for Operator:Conditional Operator

Description

Guess a random number with the ? operator

Demo Code

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

int main(void)
{
   int magic;/*  w w w. j a v a  2 s  .  c  o m*/
   int guess;

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

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

   if (guess == magic) {
      printf("** Right ** ");
      printf("%d is the magic number", magic);
   }
   else
      guess > magic ? printf("High") : printf("Low");

   return 0;
}

Result


Related Tutorials