English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2006-11-13 00:16:54 · 4 answers · asked by raghava_rss 1 in Computers & Internet Software

4 answers

Its neither long nor difficult. Here is the program, which uses recursive function to calculate gcd.

#include
#include

int find_gcd(int n1,int n2);
void main()
{
clrscr();
int number1,number2;
printf("Enter two numbers to get lcd and gcd ");
scanf("%d %d",&number1,&number2);
if((number1 <= 0) || (number2 <= 0))
{
printf("Invalid inputs");
return;
}
if(number1 == number2) {printf("GCD is %d LCD is %d",number1,number2);getch();return;}
if(number1 == 1) {printf("GCD is 1 LCD is %d",number2);getch();return;}
if(number2 == 1) {printf("GCD is 1 LCD is %d",number1);getch();return;}
int gcd = find_gcd(number1,number2);
int lcd = ((double)number1 * (double)number2)/gcd;
printf("GCD is %d and LCD is %d",gcd,lcd);
getch();

}

int find_gcd(int n1,int n2)
{
if(n1 == n2) return n1;
if(n1 == 1) return 1;
if((n2 % n1) == 0) return n1;
if(n1 < n2) return(find_gcd(n2-n1,n1));
else return(find_gcd(n1-n2,n1));
}

2006-11-15 22:57:47 · answer #1 · answered by manoj Ransing 3 · 0 0

There are quite a few procedures the for loop is the most difficulty-loose with you purely incrementing by 2 and printing the numbers that are unusual as all unusual numbers are 2 aside, nonetheless there are different procedures to do loops in C. The even as loop int i =a million; /* this contraptions the decision to at least a million */ even as ( i <= 40 9) /* If the decision is decrease than or equivalent to 40 9 the loop will proceed */ { /* begining of loop */ printf("%d ",i); /* this prints the decision the first is the decision a million*/ i+=2; /* Now upload 2 to the decision */ /*the loop will flow decrease back to the starting up */ } /* end of loop */ the subsequent one is the do even as loop not so many times used yet nonetheless a valid loop int i =a million; /* the variable i is initialised to at least a million*/ do /* commence of loop */ { printf("%d ",i); i=i+2; /* This increments by 2 or you should use i+=2; they're an similar */ } even as ( i <= 40 9) /* this checks the price no matter if that is decrease than 40 9 it is going decrease back to a loop */ Then there is the recursive - that is once you create a function that calls that is self somewhat cleverer version int count_odd(int x); /* predeclaration of function */ int significant() { int x = a million; int decision; decision =count_odd(x); printf( go back 0; } /* that is the function which returns a cost */ int count_odd(int x) { /* this contraptions the reduce to 40 9 so if the price is an similar as 40 9 it doesn't call that is self*/ if (x == 40 9 ) go back 0; else { /* prints the price of x */ printf( "%d " , x); /* the function now calls on that is self yet delivers 2 the price */ go back count_odd(x + 2); }

2016-11-29 02:27:30 · answer #2 · answered by ? 4 · 0 0

thats hard and kinda too long... i wish i can let you see my project in my c program its more of LCD gcd but i'll be on jail if sent to the world.. i hope others can help.. goodluck..mwah!

2006-11-13 00:26:20 · answer #3 · answered by chikqie 2 · 0 0

jus try sourcecode.com
uill find almost nething der...hope u get wat u wan...
hmm..im sure uill find dat..
enzoy..pgmimg...
i cud mail u the pgm if u don get it..i have it..jus send me ur mail id..
mine is lokeshvhavle@yahoo.co.uk

2006-11-13 01:24:27 · answer #4 · answered by getmeoverforever 1 · 0 0

fedest.com, questions and answers