👤

Se citesc n numere naturale. sa se determine c.m.m.d.c. -ul lor.

Răspuns :


#include "stdafx.h"#include <iostream>#include <conio.h>#pragma warning(disable: 4996)using namespace std;
int functie(int a, int b){ int c; while (b) { c = a % b; a = b; b = c; }return a;}int main(){ int a; int n; cin >> n; int *p = new int[n]; for (int i = 0; i < n; i++) { cin >> p[i]; } a= functie(p[0], p[1]); for (int i = 2; i < n; i++) { a = functie(a, p[i]); } cout << a; getch();}