Create function to find the Greatest Common Divisor - C Function

C examples for Function:Function Definition

Description

Create function to find the Greatest Common Divisor

Demo Code

#include <stdio.h>

void gcd (int u, int v){
    int temp;/* w  ww . j a v a  2s  . com*/

    printf ("The gcd of %i and %i is ", u, v);

    while (v != 0){
        temp = u % v;
        u = v;
        v = temp;
    }

    printf ("%i\n", u);
}

int main (void)
{
    gcd (10, 5);
    gcd (20, 40);
    gcd (80, 240);

    return 0;
}

Result


Related Tutorials