・ ・ ・ ・ ・ ・ ・ ・ ・ ・  前へ←トップへ戻る
そのP3. 任意の2つの数の公約数を求めてみます。(完成)

サンプルと結果


ソース(スクリプト側)
<script>
function common_divisor_p3(Form_cd_p3){

var cd1 = Form_cd_p3.select_1.value;
var cd2 = Form_cd_p3.select_2.value;
var text ='「'+cd1+'」と「'+cd2+'」の公約数は、\n';

if(cd1 > cd2) {cd_L = cd1; cd_S = cd2;}
if(cd1 < cd2) {cd_L = cd2; cd_S = cd1;}


for (i=0; i < cd_S; i++){
	cd = cd_S - i;
	cd_with_rest_L = cd_L/(cd);
	cd_check_L = cd_with_rest_L-Math.floor(cd_with_rest_L);
		if(cd_check_L == 0){
			cd_with_rest_S = cd_S/(cd);
			cd_check_S = cd_with_rest_S-Math.floor(cd_with_rest_S);
				if(cd_check_S == 0){text=text+cd+'\n';}
			}
}
	alert(text);
}
</script>

・・・・・・・・・・>もどる。