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 |
Finding a number which was log of base 2
What are the files which are automatically opened when a C file is executed?
#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }
can u give me the c codings for converting a string into the hexa decimal form......
#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }
how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.
0 Answers Mbarara University of Science and Technology,
A program that will create a movie seat reservation. The program will display the summary seats and its status. The user will be ask what seat no. to be reserved, then it will go back again to the summary to display the updated seat status. If the seat no. is already reserved then it will prompt an error message. And also if the input seat no is out of range then it will also prompt an error message. The program is continuously running. Termination of the program will depends on how the programmer will apply. Sample output: Movie Seats Reservation Summary of Seats: Seat 1: Available Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 6 The Seat no. is out of range! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 1 The Seat no. is already reserved! Movie Seats Reservation Summary of Seats: Seat 1: Reserve Seat 2: Available Seat 3: Available Seat 4: Available Seat 5: Available Enter seat no. (Press 0 to terminate Or the assigned seat capacity) : 0 GoodBye... Thank You!!!
write a function to give demostrate the functionality of 3d in 1d. function prototye: change(int value,int indexX,int indexY,int indexZ, int [] 1dArray); value=what is the date; indexX=x-asix indexY=y-axis indexZ=z-axis and 1dArray=in which and where the value is stored??
Design an implement of the inputs functions for event mode
How to use power function under linux environment.eg : for(i=1;i<=n;i++){ pow(-1,i-1)} since it alerts undefined reference to 'pow'.
How can you relate the function with the structure? Explain with an appropriate example.
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