Advertisement
Guest User

Untitled

a guest
May 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int n;
  9. cout << "Podaj liczbę n" << endl;
  10. cin >> n;
  11.  
  12. list<int> lista;
  13. for (float i = 2; i <= n; i++)
  14. {
  15. lista.push_back(i);
  16. }
  17.  
  18.  
  19. int liczba,tymczasowa;
  20.  
  21. for (int i = 0; i < sqrt(n); i++)
  22. {
  23. liczba = lista.front();
  24. lista.pop_front();
  25. lista.push_back(liczba);
  26. while (lista.front() != liczba)
  27. {
  28. tymczasowa = lista.front();
  29. lista.pop_front();
  30. if (tymczasowa % liczba != 0)
  31. {
  32. lista.push_back(tymczasowa);
  33. }
  34. }
  35.  
  36. lista.pop_front();
  37. lista.push_back(liczba);
  38. }
  39.  
  40.  
  41. // segregacja lisy
  42. int x;
  43. while (lista.front() != 2)
  44. {
  45. x = lista.front();
  46. lista.pop_front();
  47. lista.push_back(x);
  48. }
  49.  
  50. // wyświetlaie lisy
  51.  
  52. cout << "Moja lista: ";
  53. for (int i = 0; i < lista.size(); i++)
  54. {
  55. cout << lista.front() << " , " ;
  56. x = lista.front();
  57. lista.pop_front();
  58. lista.push_back(x);
  59.  
  60. }
  61. cout << endl;
  62.  
  63. getchar();
  64. getchar();
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement