GUESS GAME

 #include<stdio.h>

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

int main()
{
int n,guess,count=1;


    srand(time(0));

     n=rand()%100;

    for(count=1;guess!=n;count++)
    {
        printf("enter number:\n");
        scanf("%d",&guess);
        if(guess>n)
        {
            printf("try a smaller number\n");
        }
        else if(guess<n)
        {
            printf("try a higher number\n");

        }
        else{
            printf("you guessed it right in %d attempts\n",count);
        }
    }
    return 0;
}

Comments