Skip to content

Instantly share code, notes, and snippets.

@chankruze
Created September 6, 2019 17:39
Show Gist options
  • Save chankruze/a16fb29ce31ffdcff1c3fd662682579c to your computer and use it in GitHub Desktop.
Save chankruze/a16fb29ce31ffdcff1c3fd662682579c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
int main (){
int a, b, mod, gcd = 0;
printf("Enter Number A (Larger):\n");
scanf("%d", &a);
printf("Enter Number B (Smaller):\n");
scanf("%d", &b);
int A = a, B = b;
for(gcd; gcd == 0;){
mod = a%b;
if(mod == 0){
gcd = b;
}else{
a = b;
b = mod;
}
}
printf("Greatest Common Divisor of %d & %d is %d\n", A, B, gcd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment