⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gcd.c

📁 书名:C语言科学与艺术,以前交钱下载的
💻 C
字号:
/* * File: gcd.c * ----------- * This program computes a greatest common divisor using * a brute-force algorithm. */#include <stdio.h>#include "genlib.h"#include "simpio.h"/* Function prototypes */int GCD(int x, int y);/* Main program */main(){    int x, y;    printf("This program calculates greatest common divisors.\n");    printf("Enter two integers, x and y.\n");    printf("x = ? ");    x = GetInteger();    printf("y = ? ");    y = GetInteger();    printf("The gcd of %d and %d is %d.\n", x, y, GCD(x, y));}/* * Function: GCD * Usage: gcd = GCD(x, y); * ----------------------- * Returns the greatest common divisor of x and y, * calculated by the brute-force method of testing * every possibility. */int GCD(int x, int y){    int g;    g = x;    while (x % g != 0 || y % g != 0) {        g--;    }    return (g);}

⌨️ 快捷键说明

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