answersLogoWhite

0

pictorial representation of a program is called a flowchart

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

RossRoss
Every question is just a happy little opportunity.
Chat with Ross
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
More answers

gcd

User Avatar

Wiki User

14y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Define flowchart and draw flowchart for GCD of two numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is pseudo code for GCD of two numbers?

public class GCD { public static void main(String[] args) { //Example how to use this method System.out.println(GCD(15,50)); } //find the greatest common divisor of two numbers public static int GCD(int a, int b){ if (b == 0) return a; return GCD(b, a % b); } } Hope this help to solve you problem.


Write a method that returns the gcd of an unspecified number of integers. The method header is specified as follows public ststic int gcd int... numbers?

There are many ways of solving this problem using primitive types. However, if you are willing to sacrifice some memory, you can use BigInteger's gcd() method to make things easy. Example: public static int gcd (int[] numbers) { BigInteger k = BigInteger.ZERO; for (int n : numbers) k = k.gcd(new BigInteger(""+n)); return k.intValue(); }


How do you write a program that gives the GCD of three given numbers in C plus plus?

To find the GCD of three numbers, a, b and c, you need to find the GCD of a and b first, such that d = GCD(a, b). Then call GCD(d, c). Although you could simply call GCD(GCD(a, b), c), a more useful method is to use an array and iteratively call the GCD(a, b) function, such that a and b are the first two numbers in the first iteration, which becomes a in the next iteration, while b is the next number. The following program demonstarates this method. Note that the GCD of two numbers can either be calculated recursively or iteratively. This program includes both options, depending on whether RECURSIVE is defined or not. In a working program you'd use one or the other, but the iterative approach is usually faster because it requires just one function call and no additional stack space. The program will create 10 random arrays of integers of length 3 to 5 and process each in turn. Note that the more numbers in the array, the more likely the GCD will be 1. #include<iostream> #include<time.h> #define RECURSIVE // comment out to use iterative method #define ARRAY // comment out to use non-arrays #ifdef RECURSIVE // Returns the GCD of the two given integers (recursive method) unsigned int gcd(unsigned int a, unsigned int b) { if(!a) return(b); if(!b) return(a); if(a==b) return(a); if(~a&1) { if(b&1) return(gcd(a>>1,b)); else return(gcd(a>>1,b>>1)<<1); } if(~b&1) return(gcd(a,b>>1)); if(a>b) return(gcd((a-b)>>1,b)); return(gcd((b-a)>>1,a)); } #else // Returns the GCD of the two given integers (iterative method) unsigned int gcd(unsigned int a, unsigned int b) { if(!a) return(b); if(!b) return(a); int c; for(c=0; ((a|b)&1)==0; ++c) { a>>=1; b>>=1; } while((a&1)==0) a>>=1; do{ while((b&1)==0) b>>=1; if(a>b) { unsigned int t=a; a=b; b=t; } b-=a; }while(b); return(a<<c); } #endif RECURSIVE // Returns the greatest common divisor in the given array unsigned int gcd(const unsigned int n[], const unsigned int size) { if( size==0 ) return( 0 ); if( size==1 ) return( n[0] ); unsigned int hcf=gcd(n[0],n[1]); for( unsigned int index=2; index<size; ++index ) hcf=gcd(hcf,n[index]); return(hcf); } int main() { using std::cout; using std::endl; srand((unsigned) time(NULL)); for(unsigned int attempt=0; attempt<10; ++attempt) { unsigned int size=rand()%3+3; unsigned int* num = new unsigned int[size]; unsigned int index=0; while(index<size) num[index++]=rand()%100; unsigned int hcf=gcd(num,size); cout<<"GCD("; index=0; cout<<num[index]; while(++index<size) cout<<','<<num[index]; cout<<") = "<<hcf<<endl; delete[]num; } cout<<endl; }


How do you write a algorithm that gives the GCD of two given numbers?

algorithm GCD (a, b) is:while (a b) doif a > b then a := a - b else b := b - aend whilereturn a


How do you write a C program to find the GCD and LCM of two numbers using a switch statement?

The following function will return the GCD or LCM of two arguments (x and y) depending on the value of the fct argument (GCD or LCM). enum FUNC {GCD, LCM}; int gcd_or_lcm(FUNC fct, int x, int y) { int result = 0; switch (fct) { case (GCD): result = gcd (x, y); break; case (LCM): result = lcm (x, y); break; } return result; }