• Uncategorized

Euclid’s Algorithm C code

Euclid’s algorithm calculates the GCD (Greatest Common Divisor) for two numbers a and b. The following C program uses recursion to get the GCD.

The code is also available on GitHub.

#include <stdio.h>
 
int euclid(int a, int b) {
 if (b == 0) {
  return a;
 } else {
  return euclid(b, a % b);
 }
}
 
int main(int argc, char* argv[]) {
 int a = 30, b = 21;
 printf("GCD is %d\n", euclid(a, b));
 return 0;
}
SHARE Euclid’s Algorithm C code

You may also like...


Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Attempt to read property "cat_name" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 9

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 14

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/functions.php on line 37

Warning: Undefined array key 0 in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15

Warning: Attempt to read property "category_parent" on null in /www/wwwroot/followtutorials.com/wp-content/themes/hueman/single.php on line 15
Share