Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program Podzielnosc
- #include <iostream> using namespace std;
- int Reszta (string b, int p) { const char zero = '0';
- int dl = b.length(); //obliczenie dlugo.§ci zapisu liczby b
- int d = 0; //po zakonczeniu obliczen wartoacia d b?dzie
- // warto,e6 dziesietna liczby b modulo p
- // schemat Hornera modulo p
- for (int j = 0; j < dl; j++) {
- int cyfra = b[j] - zero; //odzyskanie kolejnej cyfry liczby
- b
- //poczynajac od najbardziej znaczacej
- d = (d*2 + cyfra)
- return d;
- int main () {
- string liczba;
- const int n = 1000;
- *p; //* jest operatorem modulo w C++
- //rozmiar danych
- int podz 2 = 0, podz 3 = 0, podz_ 5 = 0; // podz_ p - liczba
- liczb
- // podzielnych przez p
- for (int i = 0; i < n; i++) {
- cin >> liczba; //wczytanie kolejnej liczby;
- if (Reszta(liczba,2) == 0) podz 2++;
- if (Reszta(liczba,3) == 0) podz 3++;
- if (Reszta(liczba,5) == 0) podz 5++;
- cout << "podzielne przez " << 2 << " " << podz 2 << "\n";
- cout << "podzielne przez " << 3 << " : " << podz 3 << "\n";
- cout << "podzielne przez " << 5 << " : " << podz 5 << "\n";
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement