Title: Greatest common divisor of A and B
Analysis: First we need to know what greatest common divisor is, which means that two or more integers have the largest number in total. Well, know what greatest common divisor is, you can solve it, then it is equivalent to compare the number of the approximate, take its equal to the largest one on the right, right? What is the approximate??? An approximate number is one that divides a or b evenly.
All right, let's take a look at the code.
Code:
1#include <stdio.h>2 voidgcdLong intALong intb//Sub-function seeking GCD3 {4 Long inti,t=0, j=0, k=0, max,q=0;5 Long intx[ the],y[ the];//x[] A divisor that holds the first number, y[] holds the number of the second number divisible by the first divisor6 for(i=a;i>0; i--)//x[]7 {8 if(a%i==0)9x[j++]=i;Tent++; One } A for(i=0; i<t;i++)//y[] - { - if(b%x[i]==0) they[k++]=X[i]; -q++; - } -max=y[0];//Select the largest one + for(i=0; i<q;i++) - { + if(max<Y[i]) A { atmax=Y[i]; - } - } -printf"gcd=%ld\n", Max);//Output - } - voidMain () in { - Long intb; to Long intx[ -],y[ -]; + while(1) - { theprintf"Please enter the number between 0 to 255 \ n");//Enter both numbers *scanf"%ld%ld",&a,&b); $ gcd (A, b);Panax Notoginseng } -}
Let's take a look at a few answers:
Isn't it easy?
Welcome to contact My qq:2516985331
Learn together ~
C Language Beginner (4)