Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write code in C language The gcd of a list of numbers is the largest number that

ID: 646653 • Letter: W

Question

write code in C language

The gcd of a list of numbers is the largest number that evenly divides all of the elements in that list. For example, the gcd of 12 20 30 40 is 2. Write a program that takes in an arbitrary number of integers as commandline arguments and prints the gcd of that list.

Sample session:> ./a.out 101
101
> ./a.out 12 18 30
6
> ./a.out 12 18 30 36
6
> ./a.out 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
1

You may assume that at least one number is given, that the given numbers are integers, and that they are all positive (i.e. greater than 0.)

Explanation / Answer

#include int gcd(int, int); int main() { int a, b, result; printf("Enter the two numbers to find their GCD: "); scanf("%d%d", &a, &b); result = gcd(a, b); printf("The GCD of %d and %d is %d. ", a, b, result); } int gcd(int a, int b) { while (a != b) { if (a > b) { return gcd(a - b, b); } else { return gcd(a, b - a); } } return a; }}