Advertisement
wnowak8

2

Jan 28th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.     int a, b, s = 0, r, k, suma = 0;
  7.     float d;
  8.     cout << "Podaj zakres:" << endl;
  9.     cin >> a >> b;
  10.         for(int i = a; i <= b; i++) {
  11.             int w = i;
  12.             suma = 0;
  13.             do{
  14.             k = w % 10;
  15.             suma += k;
  16.             w -= k;
  17.             w /= 10;
  18.             } while (w != 0);
  19.            
  20.             if(suma!=1){
  21.             s = 0;
  22.             d = sqrt(suma);
  23.             for (int j = 2; j <= d; j++) {
  24.                 r = suma%j;
  25.                 if (r == 0) {
  26.                     s++;
  27.                 }
  28.             }
  29.             if (s == 0) {
  30.                 cout << i<<"->";
  31.             }
  32.         }
  33.  
  34.     }
  35.     system("PAUSE");
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement