codeup greatest common divisor

c++ compilation

#include <iostream>
#include <stdio.h>

using namespace std;
int gcd(int a,int b){
    
    
   if(b==0)
    return a;
   else
    return gcd(b,a%b);
  }

int main()
{
    
    
  int a,b;
  while(scanf("%d%d",&a,&b)!=EOF){
    
     //EOF可以用-1来代替
      cout<<gcd(a,b)<<endl;
  }
    return 0;
}

Note: The return value of the scanf function is the number of parameters successfully read. Only when the end of the file is reached when the file is read, the reading failure will occur. At this time, the scanf function will return -1. It is not 0, and EOF is used to represent -1 in C language.

Guess you like

Origin blog.csdn.net/weixin_43902941/article/details/105948875