HTMLify

guess_the_number.c
Views: 7 | Author: abh
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {

    srand(time(NULL));
    int number = rand() % 10000;
    int guess, attamps = 0;

    do {
        printf("Guess the number: ");
        scanf("%d", &guess);
        if (guess < number) {
            printf("Guess is lower\n");
        }
        if (guess > number) {
            printf("Guess is higher\n");
        }
        attamps++;
    } while (guess != number);
    printf("You guessed the number in %d attemps\n", attamps);

    return 0;
}

Comments