Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- using namespace std;
- int main()
- {
- int n;
- cout << "Podaj liczbę n" << endl;
- cin >> n;
- list<int> lista;
- for (float i = 2; i <= n; i++)
- {
- lista.push_back(i);
- }
- int liczba,tymczasowa;
- for (int i = 0; i < sqrt(n); i++)
- {
- liczba = lista.front();
- lista.pop_front();
- lista.push_back(liczba);
- while (lista.front() != liczba)
- {
- tymczasowa = lista.front();
- lista.pop_front();
- if (tymczasowa % liczba != 0)
- {
- lista.push_back(tymczasowa);
- }
- }
- lista.pop_front();
- lista.push_back(liczba);
- }
- // segregacja lisy
- int x;
- while (lista.front() != 2)
- {
- x = lista.front();
- lista.pop_front();
- lista.push_back(x);
- }
- // wyświetlaie lisy
- cout << "Moja lista: ";
- for (int i = 0; i < lista.size(); i++)
- {
- cout << lista.front() << " , " ;
- x = lista.front();
- lista.pop_front();
- lista.push_back(x);
- }
- cout << endl;
- getchar();
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement