write a c-program to find gcd using recursive functions

Answers were Sorted based on User's Feedback



write a c-program to find gcd using recursive functions..

Answer / pavan_mustyala

int gcdRecurse(int a, int b)
{
int temp;

// error handling to prevent divide by zero
if(!b)
{
return b;
}

temp = a % b;

if (temp == 0)
{
return(b);
}
else
{
return(gcdRecurse(b, temp));
}
}

Is This Answer Correct ?    30 Yes 11 No

write a c-program to find gcd using recursive functions..

Answer / rakib hyder

#include<stdio.h>
int gcd(int a,int b)
{
if(a==0)
return b;
else if(b==0)
return a;
else if(a>b)
return gcd(b,a%b);
else
return gcd(a,b%a);
}

Is This Answer Correct ?    12 Yes 7 No

write a c-program to find gcd using recursive functions..

Answer / arun ananda jadhav

int gcd(int num1,int num2)
{
if(nu1%num2)
{
return(gcd(num2,num1%num2));
}
else
{
return(1);
}
}

Is This Answer Correct ?    15 Yes 13 No

write a c-program to find gcd using recursive functions..

Answer / deepak

#include<stdio.h>
int main(){
int n1,n2,gcd;
printf("\nEnter two numbers: ");
scanf("%d %d",&n1,&n2);
gcd=findgcd(n1,n2);
printf("\nGCD of %d and %d is: %d",n1,n2,gcd);
return 0;
}

Is This Answer Correct ?    1 Yes 0 No

write a c-program to find gcd using recursive functions..

Answer / abilash k alex

what is gcd?

Is This Answer Correct ?    10 Yes 13 No

Post New Answer

More C Code Interview Questions

What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;

1 Answers  


main() { int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p } a. Runtime error. b. 1.00000 c. Compile error d. 0.00000

3 Answers   HCL,


Program to find the largest sum of contiguous integers in the array. O(n)

11 Answers  


#include"math.h" void main() { printf("Hi everybody"); } if <stdio.h> will be included then this program will must compile, but as we know that when we include a header file in "" then any system defined function find its defination from all the directrives. So is this code of segment will compile? If no then why?

2 Answers  


void main() { char a[]="12345\0"; int i=strlen(a); printf("here in 3 %d\n",++i); }

3 Answers  


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

0 Answers   Honeywell,


main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }

2 Answers   CSS, Wipro,


Finding a number which was log of base 2

1 Answers   NetApp,


main() { printf("%d", out); } int out=100;

3 Answers  


main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }

3 Answers  


main() { float i=1.5; switch(i) { case 1: printf("1"); case 2: printf("2"); default : printf("0"); } }

2 Answers  


main() { int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); } } a. 5, 3, 1 b. 5, 2, 1, c. 5, 3, 1, -1, 3 d. –3, -1, 1, 3, 5

2 Answers   HCL,


Categories