Sha256: 447a2ba3fc828edb30ffd541dc55f6ece7832846e7e937dfe4e18f26f65fe98b

Contents?: true

Size: 871 Bytes

Versions: 12

Compression:

Stored size: 871 Bytes

Contents

/*
 * 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);
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
picolena-0.0.99 app_generators/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.0 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.1 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.3 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.4 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.2 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.5 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.6 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.7 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.1.8 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.2.0 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c
picolena-0.2.2 lib/picolena/templates/spec/test_dirs/indexed/others/gcd.c