Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int greatestCD (int num1, int num2);
- int main(void)
- {
- int a=0, b=0;
- int result;
- printf("Please enter two numbers to calculate the greatest common denominator fromn");
- scanf("%d%d", &a, &b);
- result = greatestCD (a,b);
- printf("Using the correct in main way:nThe greatest common denominator of %d and %d is %dn",a,b, result);
- }
- int greatestCD (int num1 ,int num2)
- {
- if (num2==0){
- printf("Using the cheaty in gcd function way:nThe greatest common denominator is %dn",num1);
- return num1;
- } else {
- greatestCD(num2,(num1%num2));
- }
- }
- C:UsersSamDocumentsC programs>gcd
- Please enter two numbers to calculate the greatest common denominator from
- 12
- 15
- Using the cheaty in gcd function way:
- The greatest common denominator is 3
- Using the correct in main way:
- The greatest common denominator of 12 and 15 is 2293524
- greatestCD(num2,(num1%num2));
- return greatestCD(num2,(num1%num2));
- /dev/shm $ gcc x.c
- /dev/shm $ ./a.out
- Please enter two numbers to calculate the greatest common denominator from
- 12
- 15
- Using the cheaty in gcd function way:
- The greatest common denominator is 3
- Using the correct in main way:
- The greatest common denominator of 12 and 15 is 3
- /dev/shm $ gcc --version
- gcc (Debian 4.3.2-1) 4.3.2
- Copyright (C) 2008 Free Software Foundation, Inc.
- This is free software; see the source for copying conditions. There is NO
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Add Comment
Please, Sign In to add comment