Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <fstream>
- using namespace std;
- int main() {
- srand(time(NULL));
- int m, n;
- int x, v = 1;
- int max;
- while (v) {
- cout << "MENU\n1 - write data to file\n2 - read file and calculate\n";
- cin >> x;
- switch (x) {
- case 1: {
- cout << "input number\n";
- cin >> n;
- ofstream fi("file.txt");
- for (int i = 0; i < n; i++) {
- m = rand() % 51 - 25;
- cout << m << '\t';
- fi << m << '\t';
- }
- fi.close();
- cout << endl;
- break;
- }
- case 2: {
- int s = 0, p;
- ifstream fo("file.txt");
- while (!fo.eof()) {
- fo >> p;
- if (!fo.eof()) {
- if (p % 2 != 0) {
- max = p;
- if (max < p) {
- max = p;
- }
- }
- }
- }
- fo.close();
- cout << "Maksimalnij element sered neparnih " << max << endl;
- break;
- }
- default: v = 0;
- break;
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement