Advertisement
Guest User

podzielnosci

a guest
Nov 25th, 2014
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. //Podzielnosc 7 4 3 11
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <fstream>
  5.  
  6.  bool podzielnosc11(int liczba){
  7.     int suma;
  8.     while (liczba>0){
  9.                 suma=liczba%10+(liczba%100-liczba%10);
  10.  
  11.     if(suma%11==0)
  12.         return true;
  13.     return false;
  14.    
  15. }
  16. }
  17. using namespace std;
  18.  
  19.  bool podzielnosc2(int liczba){
  20.      int suma;
  21.      suma=liczba%10;
  22.      if(suma%2==0) return true;
  23.      return false;
  24.      }
  25.  
  26.  bool podzielnosc3 (int liczba) {
  27.      int suma;
  28.      while (liczba>0) {
  29.      suma=suma+liczba%10;
  30.      liczba=liczba/=10;
  31.      }
  32.      
  33. if (suma%3==0) return true;
  34. return false;
  35. }
  36.  
  37. bool podzielnosc7 (int liczba){
  38.          int suma=0;
  39.          int i=1;
  40.          while (liczba>0){
  41.                if (i%2==1)
  42.                   suma=suma+liczba%1000;
  43.                   else
  44.                   suma=suma-liczba%1000;
  45.                liczba=liczba/1000;
  46.                i++;
  47.                }
  48.          if(suma%7==0)
  49.             return true;
  50.          return false;
  51.          }
  52.  
  53. bool podzielnosc4 (int liczba){
  54.      int suma;
  55.      suma=liczba%10+2*liczba%100;
  56.      if(suma%4==0) return true;
  57.      return false;
  58.      }
  59.  
  60. int main(int argc, char *argv[])
  61. {  
  62.     fstream dane,wynik;
  63.     dane.open ("dane.txt", ios::in);
  64.     wynik.open ("wynik.txt", ios::out);
  65.    
  66.     int n;
  67.     while (!dane.eof()){
  68.           dane>>n;
  69.           if (podzielnosc7 (n)==true)wynik<<n<<endl;
  70.           }
  71.          
  72.     dane.close ();
  73.     wynik.close ();
  74.    
  75.     system("PAUSE");
  76.     return EXIT_SUCCESS;
  77. }
  78.  
  79. //Schody
  80. #include <iostream>
  81. #include <fstream>
  82.  
  83. using namespace std;
  84.  
  85.  
  86.  
  87. int main()
  88. {
  89.     fstream dane,wynik;
  90.     dane.open("dane.txt", ios::in);
  91.     wynik.open("wynik.txt", ios::out);
  92.     int n,k=0, liczba=n, i=1;
  93.     while(!dane.eof())
  94.     {
  95.        dane>>n;
  96.        if(n<=liczba)  
  97.         {
  98.             liczba=n;
  99.             i++;  
  100.             if(i>=k)
  101.                 k=i;
  102.         }
  103.         else
  104.         {
  105.             i=1;  (
  106.             liczba=n;
  107.         }
  108.  
  109.     }
  110.     cout<<k;
  111.  
  112.     dane.close();
  113.     wynik.close();
  114.     return 0;
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement