"Guess the Number" game in C
Here are some of the improvements i can suggest:


move your counter variable , from the inside the if statements , as increasing the count is independent of the if condition.
Use srand(time(NULL)); , below the declarations , or else , your compiler may throw this warning , when compiled using C90 standard.

warning: ISO C90 forbids mixed declarations and code [-pedantic]

So to ensure portability , avoid statements between declarations.
In the long run , more meaningful and formal names , can be used instead of names like r and guess.


In my personal opinion , these two changes would be better:


Using a break; , when the correct number is guessed , can eliminate the need for using an extra variable correct.
I would prefer to use just a  while() instead of do{}while();, if the program logic permits it.


Here is the program , modified with the changes , i listed above:

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;

int main(void) 
{

int random_num = 0;
int guessed_num = 0;
int counter = 0; 

srand(time(NULL));
random_num = rand() % 10 + 1;

printf("Guess my number! "); 

    while(1)
    {
        counter++; 

        scanf("%d", &amp;guessed_num);

        if (guessed_num == random_num) 
        {
            printf("You guessed correctly in %d tries! Congratulations!\n", counter); 
            break;
        }

        if (guessed_num &lt; random_num) 
            printf("Your guess is too low. Guess again. ");

        if (guessed_num &gt; random_num) 
            printf("Your guess is too high. Guess again. ");

    } 

return 0;   
}