kestutis

2 lygis | 1 pamokėlė | 4. Laimingi bilietai

Nov 29th, 2013
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. //Bilietai
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. const char CDfv[] = "Duomenys.txt";
  6. const char CRfv[] = "Rezultatai.txt";
  7.  
  8. //funkcijos prototipas
  9. int Atbulas(int nr);
  10.  
  11. int main() {
  12.     int n, m;           //bilieto numeriu pradzia ir pabaiga
  13.     int kiek = 0;       //keli laimingi bilietai
  14.     ifstream fd(CDfv);
  15.     fd >> n >> m;
  16.     fd.close();
  17.     for (int i = n; i <= m; i++)
  18.             if (i == Atbulas(i))
  19.             kiek++;
  20.     ofstream fr(CRfv);
  21.     fr << kiek;
  22.     fr.close();
  23.     return 0;
  24. }
  25. //funkcija: atbulai uzrasytas skaicius
  26. int Atbulas(int nr) {
  27.     int atb = 0;
  28.     int sk;
  29.     while (nr > 0) {
  30.             sk = nr % 10;
  31.             atb = atb * 10 + sk;
  32.             nr /= 10;
  33.     }
  34.     return atb;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment