・ ・ ・ ・ ・ ・ ・ ・ ・ ・  前へ←→次へトップへ戻る
その2-3. 別なオブジェクトに渡すために、結果を一行(ひとつの仮数)にまとめます。

サンプルと結果

ソース(スクリプト側)
<script>
function common_divisor_23(cd1,cd2){

var text='公約数は、';

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

	document.write(cd_L,'
'); document.write(cd_S,'
'); document.write('********************
'); 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+'*';} } } document.write(text) } </script>

ソース(呼び出し側)
common_divisor_23(24,60)

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