6

Run Settings
LanguageC++
Language Version
Run Command
#include <iostream> #include <iomanip> #include <cmath> using namespace std; void task4() { int height[12]; for (int i = 0; i < 12; i++) { height[i] = rand() % 28 + 163; cout << height[i] << " "; } cout << endl << endl; } void task39() { int Amount; cout << "Enter amount of studnts...\n"; cin >> Amount; if (Amount > 0) { int* AmountOfStudents = new int[Amount]; cout << "Enter marks of students...\n"; for (int i = 0; i < Amount; i++) { cin >> AmountOfStudents[i]; } for (int j = 0; j < Amount; j++) { cout << AmountOfStudents[j]; if (AmountOfStudents[j] > 0 && AmountOfStudents[j] <= 5) if (AmountOfStudents[j] <= 2) cout << " Student isn't allowed\n"; else cout << endl; else cout << " Mark is incorrect\n"; } } else cout << "Amount of students is 0" << endl; cout << endl; } void task74() { int Order, IfNumberLessZero = 1; double Sequence[15]; for (int i = 0; i < 15; i++) { Sequence[i] = rand() % 201 - 100; cout << Sequence[i] << " "; if (Sequence[i] < 0 && IfNumberLessZero == 1) Order = i, IfNumberLessZero = 0; } if (IfNumberLessZero == 0) cout << "\nNumber of the first negative numeral is " << Order << " (numeration from 0)"; else cout << "There is no negative numeral"; cout << endl << endl; } void task109() { int max = 0, k; double RealNumbers[6] = { 2.1, 2, 0, 33, 33.021, 7.1 }; cout << "The array is: "; for (int i = 0; i < 6; i++) { cout << RealNumbers[i] << " "; if (RealNumbers[i] > RealNumbers[max]) max = i; } cout << "(numeration from 0) \nmax element is: " << RealNumbers[max] << "\nEnter 'k' (0 <= k < 6)..." << endl; cin >> k; if (k >= 0 && k < 6) { RealNumbers[k] = RealNumbers[max]; for (int i = 0; i < 6; i++) { cout << RealNumbers[i] << " "; } } else cout << "k is incorrect"; cout << endl << endl; } void task144() { int Sequence[15], min = 0, max = 0, sum = 0; for (int i = 0; i < 15; i++) { Sequence[i] = rand() % 41; cout << Sequence[i] << " "; if (Sequence[i] < Sequence[min]) { min = i; } if (Sequence[i] > Sequence[max]) { max = i; } } if (min < max) { cout << "\nSum of "; for (int j = min; j <= max; j++) { cout << Sequence[j] << " "; sum += Sequence[j]; } } else { cout << "\nSum of "; for (int j = max; j <= min; j++) { cout << Sequence[j] << " "; sum += Sequence[j]; } } cout << endl << "is " << sum << endl << endl; } void task179() { const int R = 8, H = 4; double RealNumber[R] = { 16.3, 10.9, 12.9, 14, 6.7, 3.3, 5, 7 }; int NaturalNumber[H], counter = 0; for (int i = 0; i < R; i++) { cout << RealNumber[i] << " "; if (RealNumber[i] < int(R + H) && RealNumber[i] > int(R - H)) counter++; } int *Numbers = new int [counter]; counter = 0; cout << "\nR = 8, H = 4\nNumbers of elements which are 'R - H < El < R + H:'\n"; for (int k = 0; k < R; k++) { if (RealNumber[k] < int(R + H) && RealNumber[k] > int(R - H)) Numbers[counter] = k, counter++; } for (int j = 0; j < counter; j++) { cout << Numbers[j] << " "; } cout << " (numeration from 0)"; cout << endl << endl; } void task215() { int height[25], number; cout << "Height of 25 students is:\n"; for (int i = 0; i < 25; i++) { height[i] = rand() % 51 + 150; } for (int k = 0; k < 25; k++) { for (int j = 0; j < 25; j++) { if (height[j] < height[j + 1]) swap (height[j], height[j + 1]); } switch (k) { case 24: for (int l = 0; l < 25; l++) cout << height[l] << " "; break; } } cout << "\nEnter number of a student who has to be excluded (numeration from 0)\n"; cin >> number; if (number >= 0 && number < 25) for (int t = 0; t < 24; t++) { if (t == number) { for (int h = number; h < 24; h++) { cout << height[h + 1] << " "; } t = 25; } else cout << height[t] << " "; } else cout << "Incorrect number"; cout << endl << endl; } void task227() { cout << "Input amount of elements in sequence A, then in sequence B (amount > 0)\n"; int A = 0, B = 0, b = 0, a = 0; cin >> A >> B; if (A > 0 && B > 0) { int* sequenceA = new int[A], * sequenceB = new int[B], * sequenceAB = new int[A + B]; for (int i = 0; i < A; i++) { sequenceA[i] = rand() % 201 - 100; } for (int j = 0; j < A; j++) { for (int k = 0; k < A - 1; k++) { if (sequenceA[k] > sequenceA[k + 1]) swap(sequenceA[k], sequenceA[k + 1]); } if (j == A - 1) { for (int l = 0; l < A; l++) { cout << sequenceA[l] << " "; } } } cout << endl; for (int i = 0; i < B; i++) { sequenceB[i] = rand() % 271 - 170; } for (int j = 0; j < B; j++) { for (int k = 0; k < B - 1; k++) { if (sequenceB[k] > sequenceB[k + 1]) swap(sequenceB[k], sequenceB[k + 1]); } if (j == B - 1) { for (int l = 0; l < B; l++) { cout << sequenceB[l] << " "; } } } cout << endl; while (a < A && b < B) { if (sequenceA[a] < sequenceB[b] && a < A && b < B) cout << sequenceA[a] << " ", a++; if (sequenceA[a] > sequenceB[b] && a < A && b < B) cout << sequenceB[b] << " ", b++; if (sequenceA[a] == sequenceB[b] && a < A && b < B) cout << sequenceA[a] << " " << sequenceB[b] << " ", a++, b++; } if (a <= A - 1) for (int i = a; i < A; i++) cout << sequenceA[i] << " "; if (b <= B - 1) for (int i = b; i < B; i++) cout << sequenceB[i] << " "; } else cout << "Incorrect amount"; cout << endl << endl; } void task216() { int size, firstNegative = -1, lastEven = -1, counter = 1, k = 0, f=0; cout << "Enter the size of the array (size > 0)...\n"; cin >> size; if (size > 0) { int* array = new int[size]; for (int i = 0; i < size; i++) { array[i] = rand() % 101 - 50; cout << array[i] << " "; if (array[i] < 0 && counter == 1) firstNegative = i, counter = 0; if (array[i] % 2 == 0) lastEven = i; } if (firstNegative != -1) cout << "\nNumber of the first negative numeral is " << firstNegative + 1 << " (numeration from 1)\n"; else cout << "\nThere is no negative numearal\n"; if (lastEven != -1) cout << "Number of the last even numeral is " << lastEven + 1 << " (numeration from 1)"; else cout << "There is no even numeral"; cout << "\nDeleting first negative and last even element...\n"; while (k < size) { if (k != firstNegative && k != lastEven) cout << array[k] << " ", f++; k++; } if (f == 0) cout << "Nothing left"; } else cout << "Incorrect number"; cout << endl << endl; } int main() { int number; cout << "Numbers of tasks are 4, 39, 74, 109, 144, 179 (extra task 215, 227, 216)" << endl; while (true) { cout << "Input the number of the task (0 to close the program)..." << endl; tryagain: cin >> number; cout << endl; switch (number) { case 4: task4(); break; case 39: task39(); break; case 74: task74(); break; case 109: task109(); break; case 144: task144(); break; case 179: task179(); break; case 215: task215(); break; case 227: task227(); break; case 216: task216(); break; case 0: return 0; break; default: cout << "Incorrect number, try again" << endl; goto tryagain; break; } } }
Editor Settings
Theme
Key bindings
Full width
Lines