Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. //Program  Podzielnosc
  2. #include    <iostream> using namespace  std;
  3.  
  4. int  Reszta (string b,   int p) { const  char  zero =   '0';
  5. int  dl = b.length();   //obliczenie dlugo.§ci  zapisu liczby b
  6. int  d  =   0;  //po  zakonczeniu  obliczen  wartoacia  d b?dzie
  7. //  warto,e6  dziesietna  liczby b modulo p
  8.  
  9. // schemat Hornera modulo p
  10. for (int  j =   0;  j   < dl;  j++) {
  11. int  cyfra  =  b[j] -  zero;    //odzyskanie  kolejnej  cyfry  liczby
  12. b
  13. //poczynajac  od najbardziej  znaczacej
  14.  
  15. d =     (d*2    +  cyfra)
  16.  
  17. return  d;
  18.  
  19. int main () {
  20. string liczba;
  21. const  int  n = 1000;
  22.  
  23. *p;     //* jest  operatorem modulo  w C++
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. //rozmiar danych
  31.  
  32. int  podz   2   =   0,  podz    3   =   0,   podz_ 5    =   0;  //  podz_ p -   liczba
  33. liczb
  34. // podzielnych przez p
  35. for (int  i =   0;  i   < n;  i++) {
  36. cin >>  liczba; //wczytanie  kolejnej  liczby;
  37. if  (Reszta(liczba,2)   ==  0)  podz    2++;
  38. if  (Reszta(liczba,3)   ==  0)  podz    3++;
  39. if  (Reszta(liczba,5)   ==  0)  podz    5++;
  40.  
  41. cout    <<  "podzielne przez  " << 2    <<  "   "   << podz 2   <<  "\n";
  42. cout    <<  "podzielne przez  " << 3    <<  "   :  "    << podz 3   <<  "\n";
  43. cout    <<  "podzielne przez  " << 5    <<  "   :  "    << podz 5   <<  "\n";
  44.  
  45. return  0;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement