To seek greatest common divisor by the method of dividing, not goto

Source: Internet
Author: User
Tags greatest common divisor

1#include <iostream>2 using namespacestd;3 //Goto is not recommended, of course it is faster4 //the greatest common divisor of two numbers by the way of dividing5 intgcdLong intALong intb) {6     intX=a<b?a:b;7     //get the lesser of the constraint values used to make loops8     9      for(intI=0; i<x;x++){Ten         //Loops One       if(a>b) { A           intR=a%b;//take the remainder -           if(r==0){//can divide and judge -              returnb//can then output the}Else{//otherwise the next round of algorithms -a=b,b=R; -           } -}Else if(A&LT;B) {//Same as below +           intr=b%A; -           if(r==0){ +               returnA; A}Else{ atB=a,a=R; -           } -}Else{//two numbers equal, directly outputting one of them. -           returnA; -       } -    } in } -  to intMain () { +     inty=0; Y=GCD (156,176); -cout<<"the greatest common divisor of 156 and 176 are:"<<y; the  *     return 0; $}

To seek greatest common divisor by the method of dividing, not goto

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.