Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- using namespace std;
- int main() {
- vector<int> vec;
- ofstream steps("steps.txt");
- int n;
- std::cout << "Write a number:";
- cin >> n;
- vec.push_back(n);
- while (n != 1)
- {
- if (n % 2 == 0) {
- n = n / 2;
- vec.push_back(n);
- }
- else {
- n = 3 * n + 1;
- vec.push_back(n);
- }
- }
- int i = 0;
- while (i < vec.size()-1)
- {
- steps << vec[i] << ",";
- i++;
- // es axal xazs iwyebs texstshi yovel 10 ricxvis shemdeg, yvela step ert xazze rom ar iyos. bevri step sheidzleba daschirdes.
- if (i % 10 == 0)
- steps << endl;
- }
- steps << vec[vec.size() - 1];
- steps.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement