Write a program to determine the G.C.D of four numbers
#include <iostream>
using namespace std;
int gcd(int c,int d) {
int temp;
while(d > 0) {
temp = d;
d = c % d;
c = temp;
}
return c;
}
int main() {
int c[] = {8, 20, 32, 28};
int n = 8;
int r = c[0];
for(int i=1; i<n; i++) {
r = gcd(r, c[i]);
}
cout <<"The GCD of the four numbers is "<< r << endl;
return 0;
}
Comments
Leave a comment