《应用密码学》 欧几里得算法-Euclid

代码:

/*
ID: 53101304
PROG: Euclid
LANG: C
TIME:2012/11/6
*/
#include<stdio.h>
#include<time.h>

int Euclid(unsigned int f,unsigned int d)
{
	unsigned int x=f;
	unsigned int y=d;
	if( (x==0)&&(y==0) ) return 0;
	while(1)
	{
		if(y==0) return x;
		if(y==1) return y;
		unsigned int r = x%y;
		x=y;
		y=r;
	}
}
int main()
{
	printf("请输入所求的两个非负整数的值:\n");
	printf("(范围为0~4294967295)\n");
	unsigned int in1,in2;
	scanf("%d",&in1);
	scanf("%d",&in2);
	printf("gcb(%d,%d) = %d\n",in1,in2,Euclid(in1,in2));
	//printf("Time use = %.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

 测试结果:

(1)

(2)

(3)

(4)

展开阅读全文

没有更多推荐了,返回首页