12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- /*
- * Copyright (C) 2020, 2019, 2018, 2017 Girish M
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- */
- /*-----------------------------------
- Name:Girish M
- Roll number:cs1713
- Date:20 July 2017
- Program description: Given two positive integers, find their greatest common divisor (gcd).
- Acknowledgements: Euclid's algorithm to compute gcd of two numbers
- -----------------------------------*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- int gcd(int num1, int num2)
- {
- if(num2 == 0)
- return num1;
- else
- return gcd(num2, num1%num2);
- }
- int main(int argc, char* argv[])
- {
- if(argc == 3)
- {
- int num1 = atoi(argv[1]);
- int num2 = atoi(argv[2]);
- if((num1 >= 0) && (num2 >= 0))
- {
- if(num1 >= num2)
- printf("\nGCD of %d and %d is: %d\n", num1, num2, gcd(num1,num2));
- else
- printf("\nGCD of %d and %d is: %d\n", num1, num2, gcd(num2,num1));
- }
- }
- else
- {
- printf("\nUsage: ./cs1713-day0-prog1.o num1 num2\n");
- }
- return 0;
- }
|