Advertisement
Guest User

Untitled

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