c07.cpp

来自「此文件可以能帮你求体积」· C++ 代码 · 共 35 行

CPP
35
字号
// c07.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <stdio.h>

int main(int argc, char* argv[])
{
	int a, b, d, min, t = 0;
	
	printf( "Enter two numbers:" );
	scanf( "%d %d", &a, &b );

	min = (a>b)?b:a;
/*
	for ( d = 2; d <= min; d++ )
		if ( (a%d==0) && (b%d==0) )
			t = d;
*/
	for ( d = min; d >= 2; d-- )
		if ( (a%d==0) && (b%d==0) )
		{
			t = d;
			break;
		}

	if ( t == 0 )
		printf( "No greatest common divisior.\n" );
	else
		printf( "The greatest common divisor is %d.\n", t );

	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?