Using Repeated Subtraction Method
In this method, GCD is calculated by repeatedly subtracting the smaller value from the larger value until they become equal. If both of them become equal, then the number is the GCD.
2.1 Begin with an integer variable named num initialised with 0.
int num = 0;
2.2 Declare an integer variable named x and initialie with 2.
int x = 2;
2.3 Ask the user to input the number of integers to find the GCD of.
printf("Enter the number of integers you want to find the GCD of: ");
scanf("%d", &num);
2.4 Then, ask the user to input the numbers.
printf("Enter %d numbers:\n", num);
int arr[num];
for(int i = 0; i < num; i++)
{
scanf("%d", &arr[i]);
}
2.5 Now we can calculate the GCD by taking input values and using the repeated subtraction method. We will call the function gcd() to calculate the GCD of the input values.
int result = arr[0];
for(int i = 1; i < num; i++)
{
result = gcd(result, arr[i]);
}