Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <time.h>
- #include <cmath>
- using namespace std;
- int main()
- {
- int n, a, b, c;
- cout << "Enter the size of the array: " << endl;
- cin >> n;
- float* arr = new float[n];
- cout << "select and enter the number: 1-manual entry, 2-automatic input " << endl;
- cin >> a;
- if (a == 1) {
- cout << "Entry the element of array: " << endl;
- for (int i = 0; i < n; i++)
- {
- cin >> arr[i];
- }
- cout << endl << "Manual input array: " << endl;
- for (int i = 0; i < n; i++)
- {
- cout << " " << arr[i] << endl;
- }
- }
- else if (a == 2) {
- cout << endl << "Automatic input array: " << endl;
- srand(time(0));
- for (int i = 0; i < n; i++)
- {
- float random = ((float)rand() / RAND_MAX) * rand() - rand();
- arr[i] = random;
- cout << " " << arr[i] << endl;
- }
- }
- else {
- cout << "Try again" << endl;
- return 0;
- }
- cout << endl << "Enter the begining of interval: ";
- cin >> b;
- cout << "Enter the ending of interval: ";
- cin >> c;
- cout << endl << "Numbers in the interval:" << endl;
- int count = 0;
- for (int i = 0; i < n; i++)
- {
- if (arr[i] >= b && arr[i] <= c) {
- cout << arr[i] << "; ";
- count++;
- }
- }
- cout << endl << "Count:" << count << endl;
- float sum = 0;
- float max = arr[0];
- int arrNumber = 0;
- for (int i = 1; i < n; i++)
- {
- if (max < arr[i]) max = arr[i];
- arrNumber = i;
- }
- for (int i = arrNumber + 1; i < n; i++)
- {
- sum += arr[i];
- }
- cout << endl << "Max element in array: " << max << endl << "Amount:" << sum << endl;
- float perem;
- cout << endl << endl << "Numbers in descending order: " << endl;
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n; j++)
- {
- if (fabs(arr[i]) < fabs(arr[j]))
- {
- perem = arr[i];
- arr[i] = arr[j];
- arr[j] = perem;
- }
- }
- }
- for (int i = 0; i < n; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement