Advertisement
wnowak8

wypisanie liczby o największej liczbie dzielników z przedzia

Jan 23rd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int a, b, suma = 0, d = 0,r,f;
  8.     cout << "Podaj przedzial" << endl;
  9.     cin >> a >> b;
  10.     for (int i = a; i <= b; i++) {
  11.         suma = 0;
  12.         for (int j = 2; j <= i; j++) {
  13.             r = i % j;
  14.             if (r == 0) {
  15.                 suma++;
  16.             }
  17.         }
  18.         if (suma > d) {
  19.             d = suma;
  20.             f = i;
  21.         }
  22.     }
  23.     cout << f << endl;
  24.  
  25.  
  26.     system("PAUSE");
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement