Jump to content

File talk:Euclid flowchart.svg

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

This is the current revision of this page, as edited by 87.248.7.175 (talk) at 23:59, 18 October 2016 (Created page with 'Is this supposed to result in an infinite loop whenever A=0? <syntaxhighlight lang=C> #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) {...'). The present address (URL) is a permanent link to this version.

(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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;
}