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

int randomNumber(int min, int max)
{
    return min + rand() % (max - min + 1);
}

int main()
{
    int compGuess, userGuess;
    int chances = 3;

    srand(time(NULL));

    compGuess = randomNumber(1, 10);
    printf("%d\n", compGuess);

    do
    {
        printf("Enter your guess: ");
        scanf("%d", &userGuess);

        chances--;

        if (userGuess == compGuess)
        {
            printf("Guessed correctly\n");
            break;
        }

        if (chances == 0)
        {
            printf("Out of chances the correct number is %d\n", compGuess);
            break;
        }
    } while (chances > 0);
    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: