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 |
struct point { int x; int y; }; struct point origin,*pp; main() { pp=&origin; printf("origin is(%d%d)\n",(*pp).x,(*pp).y); printf("origin is (%d%d)\n",pp->x,pp->y); }
Is the following code legal? struct a { int x; struct a *b; }
What is your nationality?
void main() { char ch; for(ch=0;ch<=127;ch++) printf(“%c %d \n“, ch, ch); }
can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail
typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }
There is a lucky draw held every day. if there is a winning number eg 1876,then all possible numbers like 1867,1687,1768 etc are the numbers that match irrespective of the position of the digit. Thus all these numbers qualify fr the lucky draw prize Assume there is no zero digit in any numbers. write a program to show all the possible winning numbers if a "winning number"is passed as an arguments to the function.
void main() { printf(“sizeof (void *) = %d \n“, sizeof( void *)); printf(“sizeof (int *) = %d \n”, sizeof(int *)); printf(“sizeof (double *) = %d \n”, sizeof(double *)); printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *)); }
What is the output of the program given below main() { signed char i=0; for(;i>=0;i++) ; printf("%d\n",i); }
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }
write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details