TheMalva

Cuenta_digitos

Aug 25th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int cuenta_digitos(int); //Prototipo
  4.  
  5. int main()
  6. {
  7.     int entero, resultado;
  8.     do
  9.     {
  10.         printf("Ingrese un numero entero positivo: ");
  11.         scanf("%d", &entero);
  12.         if (entero <= 0)
  13.             printf("Error, el numero debe ser positivo\n");
  14.     }while(entero <= 0);
  15.  
  16.     resultado = cuenta_digitos(entero); //Llamado
  17.  
  18.     if(resultado == 1)
  19.         printf("El numero ingresado tiene mayor cantidad de pares\n");
  20.     if(resultado == 0)
  21.         printf("El numero ingresado NO tiene mayor cantidad de pares\n");
  22.  
  23.     return 0;
  24. }
  25.  
  26. int cuenta_digitos(int numero) //Definicion
  27. {
  28.     int digito=0, cant_pares=0, cant_impares=0;
  29.     do
  30.     {
  31.         digito = numero % 10;
  32.         numero = numero / 10;
  33.  
  34.         if (digito % 2 == 0)
  35.             cant_pares++;
  36.         else
  37.             cant_impares++;
  38.     }while(numero != 0);
  39.  
  40.     if(cant_pares > cant_impares)
  41.         return 1;
  42.     else
  43.         return 0;
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment