Advertisement
Five_NT

[C++]Eliminati cifrele cuprinse intre c1 si c2

Dec 7th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. //Se da un nr n. Sa se elimine toate cifrele cuprinse intre c1 si c2(c1<c2).
  2. #include <iostream.h>
  3. #include <fstream.h>
  4.  
  5. int c1, c2, x;
  6. long n;
  7.  
  8. void citire()
  9. {
  10.     ifstream f("cit.in");
  11.     f>>n;
  12.     f>>c1>>c2;
  13. }
  14.  
  15. void numar(long n, int c1, int c2, int x)
  16. {
  17.     int og=0, c=0;
  18.     while(n)
  19.     {
  20.         c=n%10;
  21.         if(c >= c1 && c <= c2)
  22.         {
  23.         }
  24.         else
  25.         {
  26.             x=x*10+c;
  27.         }
  28.         n/=10;
  29.     }
  30.     while(x)
  31.     {
  32.         og=og*10+x%10;
  33.         x/=10;
  34.     }  
  35.     cout<<og;
  36. }
  37.  
  38. int main()
  39. {
  40.     citire();
  41.     numar(n, c1, c2, x);
  42. }
  43. /* cit.in */
  44. 162448
  45. 4 7
  46.  
  47. /*
  48. Ex: n=162448, c1=4, c2=7;
  49. Valoarea furnizata este 128
  50. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement