Skip to content

Instantly share code, notes, and snippets.

@rszewczyk
Last active October 31, 2017 21:31
Show Gist options
  • Save rszewczyk/0ed2f0ed68829e43ee8d1a492b7ac36c to your computer and use it in GitHub Desktop.
Save rszewczyk/0ed2f0ed68829e43ee8d1a492b7ac36c to your computer and use it in GitHub Desktop.
GCD is C. CMSC 104
#include <stdio.h>
int main()
{
int first = 0;
int second = 0;
printf("Enter the first number: ");
scanf("%d", &first);
printf("Enter the second number: ");
scanf("%d", &second);
int larger;
int smaller;
if (first < second)
{
smaller = first;
larger = second;
}
else
{
smaller = second;
larger = first;
}
int R = larger % smaller;
while (R != 0)
{
larger = smaller;
smaller = R;
R = larger % smaller;
}
printf("The GCD of %d and %d is %d\n", first, second, smaller);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment