Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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;
- }
Advertisement
Add Comment
Please, Sign In to add comment