numbers.c
author Markus Bröker <mbroeker@largo.dyndns.tv>
Thu, 28 May 2009 16:51:26 +0200
changeset 95 d2a071bd1a60
parent 86 86b83a979d9e
child 140 05d42a3737a4
permissions -rw-r--r--
java disassembler jdisa disassembles a given java class file and shows the bytecode instructions. it does not currently output the same as javap -c <file>... committer: Markus Bröker <mbroeker@largo.homelinux.org>

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

#define getrandom(max) (1+(int)((float)(max)*rand()/RAND_MAX+1.0))

int main (void)
{
    while (1) {
        int guess = -1, value = getrandom (100), count = 0;
        do {
            printf ("Enter a number: ");
            if (scanf ("%d", &guess) < 0)
                (void)getchar ();
            else
                count++;
            if (guess != value)
                printf ("X is %s than %d\n", (value > guess) ? "higher" : "lower", guess);
        } while (value != guess);
        printf ("SUCCESS: You got it after %d attempts\n", count);
    }
    return EXIT_SUCCESS;
}