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 |
C program to print magic square of order n where n > 3 and n is odd
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 *)); }
#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }
main() { printf("%x",-1<<4); }
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.
Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all.
2 Answers Mentor Graphics, Microsoft,
How to palindrom string in c language?
Which version do you prefer of the following two, 1) printf(“%s”,str); // or the more curt one 2) printf(str);
could you please send the program code for multiplying sparse matrix in c????
main() { int a[10]; printf("%d",*a+1-*a+3); }