Seeking greatest common divisor by the method of dividing

Source: Internet
Author: User

1#include <stdio.h>2 voidSortint*PA,int*PB) {//A , B is arranged in order from large to small (using pointers to achieve "bidirectional" delivery)3     intT;4     if(*pa<*pb) {5t=*pa;*pa=*pb;*pb=T;6     }7 }8 intGcd_1 (intAintb) {//seeking greatest common divisor with the method of dividing9     intC;Ten     if(b!=0){ One          while(a%b!=0){ AC=b; -b=a%b; -A=C; the         } -     } -     returnb; - } + intGcd_2 (intAintb) {//the recursive method of dividing the Euclidean -     intC; +     if(b==0) c=A; A     Else atC=gcd_2 (b,a%b); -     returnC; - } - intMain () { -     intx,y,z,z2,*pa,*PB; -scanf"%d%d",&x,&y); inpa=&x,pb=&y;//if the *pa=x,*pb=y is changed here, then PA and PB are wild hands. - sort (PA,PB); toz=gcd_1 (x, y); +Z2=gcd_2 (x, y); -printf"%d\n%d\n", Z,Z2); the     return 0; *}

Seeking greatest common divisor by the method of dividing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.