Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- using namespace std;
- int main()
- {
- int arraySize=15, randRangeFrom=-20, randRangeTo=30;
- cout << "Enter element count: ";
- // cin >> arraySize;
- if (arraySize < 1) {
- cout << "\nCount must be posivive integer.\n\n";
- return 0;
- }
- float* arr = new float[arraySize];
- char v(0);
- cout << "\n\nHow would You like to fill in array, (M)anually or (A)utomatically? \n:";
- // cin >> v;
- v = 'A';
- if (v == 'M') {
- cout << "\nnice =)\n\n";
- for (int i = 0; i < arraySize; i++)
- {
- cout << "Enter element " << i + 1 << ": ";
- cin >> arr[i];
- }
- }
- else if (v == 'A') {
- cout << "\nYou\'re lazy =)\n\n";
- cout << "Enter initial range value: ";
- // cin >> randRangeFrom;
- cout << "Enter end range value: ";
- // cin >> randRangeTo;
- cout << endl;
- srand(time(NULL));
- for (int i = 0; i < arraySize; i++)
- {
- arr[i] = (rand() % (randRangeTo * 10 - randRangeFrom * 10 + 1) + randRangeFrom * 10) / 10.0;
- }
- }
- else {
- cout << "\nI expected \"M\" or \"A\".\nCome on, Cutie.\n\n";
- return 0;
- }
- cout << "Your array is ready and served:\n";
- for (int i = 0; i < arraySize; i++)
- {
- cout << "(" << i << ") " << arr[i] << " ";
- }
- /*
- cout << "\n\nNow starting our Variant 9 tasks:\n\n\n1. Find maximum array element by the module.\n";
- float max = fabs(arr[0]);
- for (int i = 1; i < arraySize; i++)
- {
- if (max < fabs(arr[i])) max = fabs(arr[i]);
- }
- cout << "Maximum array element by the module is: " << max;
- cout << "\n\n\n2. Calculate the sum of the elements between the first and second positive elements of the array.\nI really hope You mean (), not [] :P\n";
- bool isPositiveFound = false;
- bool isSummarizingFinished = false;
- float result = 0;
- for (int i = 0; i < arraySize; i++) {
- if (arr[i] >= 0) {
- if (isPositiveFound) {
- isSummarizingFinished = true;
- }
- else {
- isPositiveFound = true;
- }
- }
- else {
- if (isPositiveFound && !isSummarizingFinished) {
- result += arr[i];
- }
- }
- }
- if (!isSummarizingFinished) {
- result = 0;
- }
- cout << "The sum of the elements is: " << result;
- */
- for (int i = 0; i < arraySize; i++)
- {
- cout << "(" << i << ") " << arr[i] << " ";
- }
- cout << "\n\n\nRearrange the array so that the first half of the array contains all elements of odd nonpair positions and the second contains all elements of even positions. \n";
- float s;
- for (int i = 0, j = 1; j < arraySize; i = i + 1, j = j + 2)
- {
- s = arr[j];
- for (int k = j; k > i; k--)
- {
- arr[k] = arr[k - 1];
- }
- arr[i] = s;
- }
- for (int i = 0; i < arraySize; i++)
- {
- cout << arr[i] << " ";
- }
- delete[] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement