Finding the Greatest Common Divisor and Returning the Results - C Function

C examples for Function:Function Definition

Description

Finding the Greatest Common Divisor and Returning the Results

Demo Code

#include <stdio.h>

int gcd (int u, int v){
    int temp;//from  www .j  a  va 2  s.  c om

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

    return u;
}

int main (void){
    int result;

    result = gcd (15, 35);
    printf("%i\n", result);

    return 0;
}

Result


Related Tutorials