Answer to Question #242507 in C++ for felo

Question #242507

Write a program to determine the G.C.D of four numbers

1
Expert's answer
2021-09-26T11:42:10-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS