IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CAdvanced Functions : Recursive GCD
<06.15>
#include <stdio.h> //Finds the greatest common divisor of m and n //m and n are both > 0 int gcd (int m, int n) { int ans; if (m % n == 0) ans = n; else ans = gcd(n, m % n); return (ans); } int main (void) { int n1, n2; printf("Enter two positive integers separated by a space> "); scanf("%d%d", &n1, &n2); printf("Their greatest common divisor is %d\n", gcd(n1, n2)); return (0); }
Hergestellt in Deutschland / Made in Germany
Enter two positive integers separated by a space > 24 84 Their greatest common divisor is 12
COPYRIGHT © 2015-2024 IHY PRESS Frankfurt am Main 60329 Deutschland