Advertisement
Fran0031

Ejemplo d.15/11

Nov 15th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. bool is_even(int x){
  4.     printf("\tis_even(%d)\n", x);
  5.  
  6.     if (x == 0)
  7.         return true;
  8.     else{
  9.         bool tmp = !is_even(x-1);
  10.     return tmp;
  11.     }
  12. }
  13. int main(){
  14.     int x;
  15.     printf("Introduce un numero positivo: ");
  16.     scanf("%d", &x);
  17.     if (is_even(x))
  18.         printf("%d es par\n",x);
  19.     else
  20.         printf("%d es impar\n",x);
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement