Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int gcd(int a, int b);
- int func(int* arr, int n);
- int main()
- {
- int n;
- cout << "Enter n: ";
- cin >> n;
- int a[n];
- cout << "Enter " << n << " numbers: ";
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- }
- cout << "Result: " << func(a, n) << endl;
- return 0;
- }
- int gcd(int a, int b) {
- while (b != 0) {
- a %= b;
- swap(a, b);
- }
- return a;
- }
- int func(int* arr, int n)
- {
- int m = 0;
- for (int i = 0; i < n; i++)
- {
- if (arr[i] >= 2)
- {
- arr[m] = arr[i];
- m++;
- }
- }
- n = m;
- if (n == 0)
- {
- return 0;
- }
- int gcdNum = arr[0];
- for (int i = 0; i < n; i++)
- {
- gcdNum = gcd(arr[i], gcdNum);
- }
- return gcdNum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement