Finding the Greatest Common Divisor - C Statement

C examples for Statement:while

Description

Finding the Greatest Common Divisor

Demo Code

#include <stdio.h>

int main (void)
{
    int u, v, temp;

    printf ("Please type in two nonnegative integers.\n");
    scanf ("%i%i", &u, &v);

    while (v != 0) {
        temp = u % v;//  ww  w .j  a v a2 s.c o m
        u = v;
        v = temp;
    }

    printf ("Their greatest common divisor is %i\n", u);

    return 0;
}

Result


Related Tutorials