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 many processes will gate created execution of -------- fork(); fork(); fork(); -------- Please Explain... Thanks in advance..!
void main() { int i=5; printf("%d",i++ + ++i); }
main() { int i=5,j=6,z; printf("%d",i+++j); }
#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }
Under linux environment can u please provide a c code for computing sum of series 1-2+3-4+5......n terms and -1+2-3+4-5...n terms..
Question: We would like to design and implement a programming solution to the reader-writer problem using semaphores in C language under UNIX. We assume that we have three readers and two writers processes that would run concurrently. A writer is to update (write) into one memory location (let’s say a variable of type integer named temp initialized to 0). In the other hand, a reader is to read the content of temp and display its content on the screen in a formatted output. One writer can access the shared data exclusively without the presence of other writer or any reader, whereas, a reader may access the shared memory for reading with the presence of other readers (but not writers).
What is the hidden bug with the following statement? assert(val++ != 0);
void main() { void *v; int integer=2; int *i=&integer; v=i; printf("%d",(int*)*v); }
could you please send the program code for multiplying sparse matrix in c????
What are the files which are automatically opened when a C file is executed?
to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD
Sorting entire link list using selection sort and insertion sort and calculating their time complexity
1 Answers Infosys, Microsoft, NetApp,