TheMalva icon

Cuenta_digitos

TheMalva | PRO | 08/25/17 02:40:40 PM UTC | 0 ⭐ | 180 👁️ | Never ⏰ | []
C |

960 B

|

None

|

0 👍

/

0 👎

#include<stdio.h>
 
int cuenta_digitos(int); //Prototipo
 
int main()
{
    int entero, resultado;
    do
    {
        printf("Ingrese un numero entero positivo: ");
        scanf("%d", &entero);
        if (entero <= 0)
            printf("Error, el numero debe ser positivo\n");
    }while(entero <= 0);
 
    resultado = cuenta_digitos(entero); //Llamado
 
    if(resultado == 1)
        printf("El numero ingresado tiene mayor cantidad de pares\n");
    if(resultado == 0)
        printf("El numero ingresado NO tiene mayor cantidad de pares\n");
 
    return 0;
}
 
int cuenta_digitos(int numero) //Definicion
{
    int digito=0, cant_pares=0, cant_impares=0;
    do
    {
        digito = numero % 10;
        numero = numero / 10;
 
        if (digito % 2 == 0)
            cant_pares++;
        else
            cant_impares++;
    }while(numero != 0);
 
    if(cant_pares > cant_impares)
        return 1;
    else
        return 0;
 
 
}

Comments