Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <math.h>
- using namespace std;
- int main() {
- int n;
- int userChoice;
- int lowestValue;
- int highestValue;
- double* arr;
- cout << "Array element count:" << endl;
- cin >> n;
- arr = new double[n];
- cout << "1 - manual 2 - auto" << endl;
- cin >> userChoice;
- if (userChoice == 2) {
- do {
- cout << "Minimal element" << endl;
- cin >> lowestValue;
- cout << "Maximal element" << endl;
- cin >> highestValue;
- } while (lowestValue > highestValue);
- }
- srand(time(NULL));
- for (int i = 0; i < n; i++) {
- if (userChoice == 1) {
- cout << "Enter " << i + 1 << " array element:" << endl;
- cin >> arr[i];
- }
- if (userChoice == 2) {
- arr[i] = lowestValue + (rand() % (highestValue * 100 - lowestValue * 100 + 1) / 100.000);
- }
- }
- for (int i = 0; i < n; i++) {
- cout << " | " << arr[i] << " ";
- }
- int maxValue = 0;
- int maxIndex;
- for (int i = 0; i < n; i++) {
- if (arr[i] > maxValue) {
- maxValue = arr[i];
- maxIndex = i;
- }
- }
- cout << "Max value index: " << maxIndex << endl;
- int zeroCount = 0;
- double reiz = 0;
- for (int x = 0; x < n; x++) {
- if (arr[x] == 0) {
- zeroCount++;
- continue;
- }
- if (zeroCount == 1) {
- reiz *= arr[x];
- }
- else if (zeroCount == 2) {
- break;
- }
- }
- cout << "res: " << reiz << endl;
- int i, j, pass = 0;
- double temp;
- bool done = false;
- int lastIndex = 0;
- while (!done) {
- lastIndex = 0;
- for (int i = 0; i < n - 1; i++) {
- if ((int)arr[i] % 2 == 0 && (int)arr[i + 1] % 2 != 0) {
- temp = arr[i + 1];
- arr[i + 1] = arr[i];
- arr[i] = temp;
- break;
- }
- else {
- lastIndex++;
- }
- if (lastIndex == n - 1) {
- done = true;
- }
- }
- }
- cout << endl;
- for (int x = 0; x < n; x++) {
- cout << arr[x] << ", ";
- }
- delete[] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement