Last active
October 31, 2017 21:31
-
-
Save rszewczyk/0ed2f0ed68829e43ee8d1a492b7ac36c to your computer and use it in GitHub Desktop.
GCD is C. CMSC 104
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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