each of the two consecutive elements of an array, whose length should be defined as a
constant, and prints them. Also write a
function GCD(a, b) that would take the two consecutive elements of the array as
arguments and return the GCD.
I have done it without making a function because the function can be made easily the main problem is i can't seem to get the calculations right. please help me in this program.
Code:
#include<stdio.h>
#include<conio.h>
const arr[10];
void GCD (int a, int b);
int main (void)
{
double arr[10], n, temp, remainder, gcd=0;
clrscr();
for (n=0;n<10;n++)
{
printf("Enter A Number = ");
scanf("%lf",&arr[n]);
}
for (n=0;n<10;n++)
{
if (arr[n] == 0 || arr[n+1] == 0)
{
printf("Division By 0 Is Not Possible\n");
}
if (arr[n] == 1 || arr[n+1] == 1)
{
printf("The GCD is 1\n");
}
if (arr[n+1] > arr[n])
{
temp = arr[n];
arr[n] = arr[n+1];
arr[n+1] = temp;
}
}
for (n=0;n<10;n++)
{
if ((arr[n] / arr[n+1]) > 0)
{
remainder = (arr[n] * arr[n+1]);
gcd++;
printf("The GCD#%0.0f Is = %0.0f\n",gcd, remainder);
}
}
while (remainder != 0)
{
remainder = (arr[n] % arr[n+1]);
arr[n] = arr[n+1];
arr[n+1] = remainder;
printf("%d\n",arr[n]);
}
printf("The GCD#%d Is %d\n",n,arr[n]);
}
getch();
return(0);
}


