Advertisement
KuoHsiangYu

answer_Suresh_Kumar_question.cpp

Jan 31st, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. /*
  2. answer_Suresh_Kumar_question
  3. Suresh Kumar C , C++ , C# , Java, SQL , VB. net, Python , MVC , Web Programming
  4. 新成員 · 14小時 ·
  5.  
  6. My program is not showing correct results.it is compiling successfully. please tell me the error.
  7. https://www.facebook.com/groups/prog11/permalink/2482225488515644/
  8. */
  9.  
  10. #include <cstdio>
  11. #include <iostream>
  12.  
  13. using namespace std;
  14.  
  15. int main(int argc, char *argv[]) {
  16.     int min = 0, max = 0;
  17.     bool flag = true;
  18.     cout << "enter the lower limit of number: ";
  19.     cin >> min;
  20.     cout << "enter the upper limit of number: ";
  21.     cin >> max;
  22.     if (max <= min) {
  23.         cout << "Error, upper limit must larger than lower limit." << endl;
  24.         return -1;
  25.     }
  26.     if (min < 2) {
  27.         min = 2;
  28.     }
  29.  
  30.     /* Look at here. */
  31.     for (int i = min; i <= max; i++) {
  32.         flag = true;
  33.         for (int j = 2; j < i; j++) {
  34.             if (i%j == 0) {
  35.                 flag = false;
  36.                 break;
  37.             }
  38.         }
  39.         if (flag == true) {
  40.             cout << i << ", ";
  41.         }
  42.     }
  43.     cout << endl << "are prime out if given elements" << endl;
  44.     while (getchar() != '\n' && getchar() != EOF);/* Clear buffer */
  45.     cout << "Press enter to continue . . . ";
  46.     getchar();
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement