Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <cstdlib>
- #include <cstdlib>
- using namespace std;
- void Show(int A[], int n)
- {
- int Max = 0, max, x = n + 1;
- for (int i = 0; i < n; i++)
- {
- max = 0;
- for (int j = i; j < n - 1; j++)
- {
- if (A[j+1] % A[j] == 0)
- {
- max = j + 1;
- }
- else
- {
- break;
- }
- }
- if(Max < abs(Max - max))
- {
- Max = max;
- x = i;
- }
- }
- cout << "Максивальнно длинная строка: ";
- for (int i = x; i <= Max; i++)
- {
- cout << A[i] << " ";
- }
- }
- int main()
- {
- setlocale(0,"RUS");
- int A[100] = {}, n;
- cout << "Введите длинну последовательности: ";
- cin >> n;
- if(n > 0)
- {
- for (int i = 0; i < n; i++)
- {
- s:
- cout << "Введите " << i + 1 << " число: ";
- cin >> A[i];
- if(A[i] <= 0)
- {
- cout << "Ошибка ввода" << endl;
- goto s;
- }
- }
- cout << "Последовательность: ";
- for (int i = 0; i < n; i++)
- {
- cout << A[i] << " ";
- }
- cout << endl;
- if (n > 1)
- {
- Show(A, n);
- }
- else
- {
- cout << "Максивальнно длинная строка: " << A[0] << endl;
- }
- cout << endl;
- system("pause");
- }
- else
- {
- cout << "Введите данные корректно!" << endl;
- }
- return main();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement