Skip to content

Instantly share code, notes, and snippets.

@TrevorMcCormick
Created November 4, 2014 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TrevorMcCormick/ea38fa11340d705098e7 to your computer and use it in GitHub Desktop.
Save TrevorMcCormick/ea38fa11340d705098e7 to your computer and use it in GitHub Desktop.
Finds greatest common divisor of two nonnegative integer values
// Program to find the greatest common divisor of two nonnegative integer values
#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;
u = v;
v = temp;
}
printf ("Their greatest common divisor is %i\n", u);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment