Untitled
unknown
c_cpp
3 years ago
1.5 kB
5
Indexable
//=================================================================== // name : ex4b.cc // author : yehuda keller // id : 314699497 // created in : 15/11/2021 // description :The program builds a series, given an even // number then next will be the number divided by two, // otherwise the number is multiplied by three plus one //******************************************************************* //------------ * include section * --------------- #include <iostream> #include <cstdlib> //------------ * using section * ----------------- using std::cin; using std::cout; using std::endl; //------------ * const section * ----------------- const int SERIES_SIZE = 25; const int MAX = 1000; //------------ * main section * ------------------ int main() { bool occur[SERIES_SIZE];//bool arry int index = 0,// index for the loop x = 0,//the first cell temp = 0; for (index = 0; index < MAX; index++) occur[index] = false; for (x = 1; x < SERIES_SIZE; x++) { cout << occur[temp]<< " " << x <<"one \n"; temp = x; while (temp <= MAX && !occur[temp]) { cout << temp << " "; occur[temp] = true; if (temp % 2 == 0) { temp = temp / 2; } else { temp = (temp * 3 + 1); } } cout << temp << endl; } cout << endl; return EXIT_SUCCESS; }
Editor is loading...