Only taking 1 input.. then stopped working error .. plz help me............ and plz point out other mistakes too. I will be grateful to you for the help...
here is the question
#1: Write a program that calculates the gcd’s (greatest common divisors) of each of the two consecutive elements of an array of size n and prints them as shown in the example Problem below. For this you have to write a function gcdMulti(int[]) that would take the integer array as argument, the array size and print the GCD of the consecutive elements. Furthermore, gcdMulti() must call gcd() which returns the GCD of two integers. Identify the complete signatures of each of these functions and implement them.
Example:
Input:
2 4 6 3 9
Output:
GCD1=2; GCD2=2; GCD3=3; GCD4=3
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
//--gcdMulti Definition--
void gcdMulti(int arr[],int size){
int i=0;
int stor=0;
for(i=0; i<size; i++){
stor=gcd((arr+i),(arr+(i+1)));
}
printf("GCD: %d \n",stor);
}
//**gcdMulti def End**
//---------------------
//--gcd definition--
int gcd(int a,int b){
int temp,stor;
if(b < a){
temp=a;
a=b;
b=temp;
}
for(temp=0; temp<a; temp++){
if(a%temp == 0 && b%temp==0){
stor=temp;
}
}
return stor;
}
//**gcd def END**
//---------------------
//--Int main--
int main()
{
int *arr,size,i;
arr=(int *)malloc(size*sizeof(int));
printf("Enter the no of value: ");
scanf("%d",&size);
printf("Enter %d values: ",size);
for(i; i<size; i++){
scanf("%d",*(arr+i));
}
gcdMulti(arr,size);
free(arr);
getch();
return 0;
}
//**int main END**