Skip to content

Instantly share code, notes, and snippets.

@Wesitos
Last active August 29, 2015 14:07
Show Gist options
  • Save Wesitos/d3e3d761b440fc61e134 to your computer and use it in GitHub Desktop.
Save Wesitos/d3e3d761b440fc61e134 to your computer and use it in GitHub Desktop.
#include<stdio.h>
long long ocurrencias(long long n, char cif, long long suma);
int main()
{
char cif;
long long num;
do
{
printf("Ingrese una cifra: ");
scanf("%hhd", &cif);
} while ( cif < 0 && cif > 9);
printf("Ingrese un numero: ");
scanf("%Ld", &num);
long long suma=0, aux=num;
while(aux > 0)
{
if (aux%10 == cif)
suma++;
aux/= 10;
}
printf("La cantidad de veces que aparece %hhd es: %Ld\n", cif, suma);
printf("Recursivo: %Ld\n", ocurrencias(num,cif,0));
}
long long ocurrencias(long long n, char cif, long long suma)
{
if(n == 0)
return suma;
else
{
if ( cif == n%10)
suma++;
n /= 10;
return ocurrencias(n, cif, suma);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment