File talk:Euclid flowchart.svg

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Is this supposed to result in an infinite loop whenever A=0?

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
	int a, b;

	if (argc != 3) {
		return EXIT_FAILURE;
	}

	a = atoi(argv[1]);
	b = atoi(argv[2]);

	while (b != 0) {
		if (a > b) {
			a = a - b;
		} else {
			b = b - a;
		}
	}

	printf("%d\n", a);

	return EXIT_SUCCESS;
}