Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me with my homework. Below will be the basic code, please complete those 'TO DO' 1, 2 and 3 and not change the

Please help me with my homework. Below will be the basic code, please complete those 'TO DO' 1, 2 and 3 and not change the other part of the code. The question will also be attached below. Thank you.

#include

using namespace std;

const int LEN = 5;

// TODO 1: Complete the function declaration of GCD(), takes 2 interger as parameter.

int GCD(){

// TODO 2: Complete the function implementation, return the GCD of 2 given number

}

int main(){

int Num[LEN];

int answer;

cout

for(int i = 0; i

cin >> Num[i];

}

cout

answer = Num[0];

for(int i = 1; i

// TODO 3: Complete the loop, to get the GCD of all input numbers.

}

cout

return 0;

}

image text in transcribed
lab08.pdf - Adobe Acrobat Pro X File Edit View Window Help Create Customize 3 13 IK + 90% They Tools Sign Comment Q3. (to be marked) Download GCD . epp. The program intends to find the Greatest Common Divisor of a set of input positive integers. The Greatest Common Divisor is the largest positive integer that divides each of the integers, e.g. the GCD of {4, 6} is 2 and the GCD of {12, 24, 6} is 6. The program saves input numbers in array Num [ ]- Your task is as follows: - Complete the GCD( ) function which return the greatest common divisor of two numbers. - Complete the loop in main function, using GCDO to find the greatest common divisor of all input numbers. - Do not modify attributes in the program. Hint: You can use Euclidean algorithm to get the GCD of two integers. Expected Outputs: Example-1 Example-2 Enter 5 numbers: Enter 5 numbers: 2 4 6 8 10 12 24 6 36 60 GCD: GCD: 2 6 Example-3 Example-4 Enter 5 numbers: Enter 5 numbers: 12 24 8 36 100 16 25 14 7 30 GCD : GCD: 4 1 Type here to search w X P 9 ENG 9:04 PM 3/22/2020

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions