~ruther/verilog-riscv-semestral-project

bb32d2ddcd68d2cf131760d9c1d99f9107c912f8 — Rutherther 1 year, 5 months ago 9f4ac4d
feat: add gcd program for testing
1 files changed, 44 insertions(+), 0 deletions(-)

A programs/gcd.c
A programs/gcd.c => programs/gcd.c +44 -0
@@ 0,0 1,44 @@
#ifdef unix
#include <stdio.h>
#endif

int int_remainder(int a, int b) {
    while (a >= b) {
        a -= b;
    }

    return a;
}

int gcd(int a, int b)
{
    int previous_r = b;

    int current_r;
    while ((current_r = int_remainder(a, previous_r)) != 0) {
        a = previous_r;
        previous_r = current_r;
    }

    return previous_r;
}

void main()
{
    int a = 1071;
    int b = 462;

    #ifdef unix
    printf("a: ");
    scanf("%d", &a);
    printf("b: ");
    scanf("%d", &b);
    #endif

    int res = gcd(a, b);

    #ifdef unix
    printf("%d\n", res);
    #endif

}

Do not follow this link