write a c-program to find gcd using recursive functions
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
How do you write a program which produces its own source code as its output?
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
why java is platform independent?
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }
How to read a directory in a C program?
print numbers till we want without using loops or condition statements like specifically(for,do while, while swiches, if etc)!
C statement to copy a string without using loop and library function..
Design an implement of the inputs functions for event mode
how can i search an element in an array
2 Answers CTS, Microsoft, ViPrak,
#include<stdio.h> main() { FILE *ptr; char i; ptr=fopen("zzz.c","r"); while((i=fgetch(ptr))!=EOF) printf("%c",i); }
main() { int i=5; printf("%d",++i++); }
How to count a sum, when the numbers are read from stdin and stored into a structure?