Advertisement
rotti321

ElimCifRec

Oct 18th, 2017
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. /// ElimCifRec
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int elimcif_iterativ(int n,int c)
  7. {
  8. int x,p=1,cifra;
  9. x=0;
  10. while(n>0){
  11. cifra=n%10;
  12. if(cifra!=c){
  13. x = x + cifra * p;
  14. p = p * 10;
  15. }
  16. n=n/10;
  17. }
  18. return x;
  19. }
  20.  
  21. int elimcif(int n , int c)
  22. {
  23. if(n == 0)
  24. return n;
  25. else
  26. if(n % 10 == c)
  27. return elimcif(n / 10 , c);
  28. else
  29. return elimcif(n / 10 , c) * 10 + n % 10;
  30. }
  31. int fact(int n)
  32. {
  33. if(n==0) return 1;
  34. return fact(n-1)*n;
  35. }
  36.  
  37. int main(){
  38.  
  39. int nr,c;
  40. cout<<fact(3)<<endl;
  41. nr=2547222; c=2;
  42. cout<<elimcif(nr,c);
  43.  
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement