Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int nod(int n, int m)
- {
- if (m == 0)
- return n;
- if (n > m)
- return nod(m, n - m);
- else
- return nod(n, m - n);
- }
- void ex1() {
- int n, ch = 1;
- int nod_;
- cout << "Введите количество чисел" << endl;
- cin >> n;
- int* arr = new int[n];
- for (int i = 0; i < n; i++) {
- cout << "Введите " << i + 1 << " число" << endl;
- cin >> arr[i];
- }
- if (n >= 2) {
- nod_ = nod(arr[0], arr[1]);
- }
- else {
- nod_ = arr[0];
- }
- for (int i = 2; i < n; i++) {
- nod_ = nod(nod_, arr[i]);
- }
- for (int i; i < n; i++) {
- ch *= arr[i];
- }
- cout << "Наибольший общий делитель " << nod_ << endl;
- cout << "Наименьший общиее кратное " << ch / nod_ << endl;
- }
- void ex2() {
- int x, y, z, temp;
- cout << "x= ";
- cin >> x;
- cout << "y= ";
- cin >> y;
- z = x + y;
- int *arr1 = new int[x];
- int *arr2 = new int[y];
- int* arr3 = new int[z];
- for (int i = 0; i < x; i++) {
- cin >> arr1[i];
- }
- for (int i = x - 1; i >= 1; i--) {
- for (int j = 0; j < i; j++) {
- if (arr1[j] > arr1[j + 1]) {
- temp = arr1[j];
- arr1[j] = arr1[j + 1];
- arr1[j + 1] = temp;
- }
- }
- }
- temp = 0;
- for (int i = 0; i < y; i++) {
- cin >> arr2[i];
- }
- for (int i = y - 1; i >= 1; i--) {
- for (int j = 0; j < i; j++) {
- if (arr2[j] > arr2[j + 1]) {
- temp = arr2[j];
- arr2[j] = arr2[j + 1];
- arr2[j + 1] = temp;
- }
- }
- }
- temp = 0;
- for (int i = 0; i < z; i++) {
- if (i < x) {
- arr3[i] = arr1[i];
- }
- else {
- arr3[i] = arr2[i - x];
- }
- }
- for (int i = z - 1; i >= 1; i--) {
- for (int j = 0; j < i; j++) {
- if (arr3[j] > arr3[j + 1]) {
- temp = arr3[j];
- arr3[j] = arr3[j + 1];
- arr3[j + 1] = temp;
- }
- }
- }
- for (int i = 0; i < z; i++) {
- cout << arr3[i] << " ";
- }
- cout << endl;
- delete arr1;
- delete arr2;
- delete arr3;
- }
- int main() {
- setlocale(0, "");
- // ex1();
- // ex2();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement