[ create a new paste ] login | about

Link: http://codepad.org/ylcVwt3v    [ raw code | output | fork ]

박정욱 - C, pasted on Apr 12:
//수치계산 목678 박정욱
//gcd 구하기
#include<stdio.h>

int main()
{
	//r1= qr2 + r3	; (r1,r2) = (r2,r3)
	int r1,r2,r3,q;

	printf("input A : ");	scanf("%d",&r1);
	printf("input B : ");	scanf("%d",&r2);

	do
	{
		r3= r1%r2;
		//		r1 = r2 * q  + r3
		printf("%d = %d * %d + %d\n",r1,r2,r1/r2,r3);
		r1=r2;
		r2=r3;
	
	}while(r3!=0);

	printf("gcd = %d \n", r1);
	return 0;
}


Output:
1
2
3
4
5
6
7
input A : input B : 134514064 = 134513710 * 1 + 354
134513710 = 354 * 379982 + 82
354 = 82 * 4 + 26
82 = 26 * 3 + 4
26 = 4 * 6 + 2
4 = 2 * 2 + 0
gcd = 2 


Create a new paste based on this one


Comments: