Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void swap(int *a, int *b){
- int temp = *a;
- *a = *b;
- *b = temp;
- }
- int gcd(int a, int b){
- if(a < b) swap(&a, &b);
- int r = a % b;
- printf("\n%d\t=\t%d\t*\t%d\t+\t%d", a, a/b, b, r);
- if (r == 0) return b;
- gcd (b, r);
- }
- int main(){
- printf("Enter two numbers to find out their GCD:-\n");
- int a, b;
- scanf("%d", &a);
- scanf("%d", &b);
- printf("\n\nSo, %d is the GCD of %d and %d\n", gcd(a, b), a, b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement