Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Guess my number in C
#include <stdio.h>
void guess(int n, int low, int upper){
int guess_number = (upper + low) / 2;
if(guess_number < n){
printf("Tu número no es %d\n", guess_number);
guess(n, guess_number, upper);
}
if(guess_number > n){
printf("Tu número no es %d\n", guess_number);
guess(n, low, guess_number);
}
if(guess_number == n)
printf("Tu número es %d\n", guess_number);
}
int main(){
int low_limit = 0;
int upper_limit = 1000;
printf("Hola mundo!!!!\n");
guess(813, low_limit, upper_limit);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment