//辗转相除法求两数的最大公约数(c语言)
int divisor(int a,int b){
int temp;if(a<b){
temp=a;
a=b;
b=temp;}while(b!=0){//通过循环求两数的余数,直到余数为0
temp=a%b;
a=b;
b=temp;}return a;//返回最大公约数}//嵌套求两数的最小公倍数
int multiple(int a,int b){
int divisor(int a,int b);
int temp;
temp=divisor(a,b);//求出最大公约数return(a*b/temp);//返回最小公倍数}
键盘输入若干对整数x、y,求其相应的最大公约数。
运行后若输入:
18128121012
则结果输出:
642;*【*/.386.model flat, stdcall
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib
printf PROTOC:ptr sbyte,:vararg
scanf PROTOC:ptr sbyte,:vararg
option casemap :none
.data
infmt BYTE'%d %d',0
outfmt BYTE'%d',13,0
x DWORD?
y DWORD?
min dword ?
max dword ?
t dword ?
re dword ?.code
start:
invoke scanf ,addr infmt ,addr x,addr y
.whileEAX==2MOV t,1FEQU=40H
FLESS=1FLD x
FCOMP y
fnstsw ax
.if ah&FLESS;x<y
mov eax,y
mov max,eax
mov eax,x
mov min,eax
.else
mov eax,x
mov max,eax
mov eax,y
mov min,eax
.endif
.while t!=0
mov eax,max
cdq
idiv min
.if edx==0
mov t,edx
mov ebx,min
mov re,ebx
.else
mov ebx,min
mov max,ebx
mov eax,edx
mov min,eax
.endif
.endw
;FLD x ;求最小公倍数
;FMUL y
;FDIV re
;FSTP re
invoke printf ,addr outfmt,re
invoke scanf ,addr infmt ,addr x,addr y
.endw
ret
end start
;*】*/
键盘输入若干对整数x、y,求其相应的最小公倍数。
运行后若输入:
18128121012
则结果输出:
362460.386.model flat, stdcall
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib ;引用C库文件
printf PROTOC:ptr sbyte,:vararg ;C语言printf函数原型声明
scanf PROTOC:ptr sbyte,:vararg ;C语言scanf函数原型声明
option casemap :none
;*【*/.data
infmt BYTE'%d %d',0
outfmt BYTE'%d',13,0
x DWORD?
y DWORD?
min dword ?
max dword ?
t dword ?
re dword ?.code
start:
invoke scanf ,addr infmt ,addr x,addr y
.whileEAX==2MOV t,1FEQU=40H
FLESS=1FLD x
FCOMP y
fnstsw ax
.if ah&FLESS;x<y
mov eax,y
mov max,eax
mov eax,x
mov min,eax
.else
mov eax,x
mov max,eax
mov eax,y
mov min,eax
.endif
.while t!=0
mov eax,max
cdq
idiv min
.if edx==0
mov t,edx
mov ebx,min
mov re,ebx
.else
mov ebx,min
mov max,ebx
mov eax,edx
mov min,eax
.endif
.endw
fld x
fmul y
fdiv re
fstp re
invoke printf ,addr outfmt,re
invoke scanf ,addr infmt ,addr x,addr y
.endw
ret
end start
;*】*/
键盘输入若干对实数x、y,求各对实数乘积和。
运行后若输入:
2.521.542.22
则结果输出:
15.4;*【*/.386.model flat, stdcall
option casemap :none
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib ;引用C库文件
printf PROTOC:ptr sbyte,:vararg ;C语言printf函数原型声明
scanf PROTOC:ptr sbyte,:vararg ;C语言scanf函数原型声明
.data
infmt byte '%lf %lf',0
outfm byte '%g',13,10,0
x qword ?
y qword ?
m qword ?
md qword 0.0.code
start:
fld md
invoke scanf ,addr infmt,addr x,addr y
.while eax==2
fld x
fmul y
fstp m
fadd m
invoke scanf ,addr infmt,addr x,addr y
.endw
fstp md
invoke printf,addr outfm,md
invoke ExitProcess,0
end start
;*】*/
键盘输入若干实数,求其和。
运行后若输入:
1.22.33.4
则结果输出:
6.9.386.model flat, stdcall
include kernel32.inc
includelib kernel32.lib
includelib msvcrt.lib ;引用C库文件
printf PROTOC:ptr sbyte,:vararg ;C语言printf函数原型声明
scanf PROTOC:ptr sbyte,:vararg ;C语言scanf函数原型声明
option casemap :none
;*【*/.data
infmt byte '%lf',0
outfmt byte '%g',13,10,0
n qword ?
re qword ?.code
start:
fld re
invoke scanf,addr infmt,addr n
.while eax==1
fadd n
invoke scanf ,addr infmt,addr n
.endw
fstp re
invoke printf,addr outfmt,re
invoke ExitProcess,0
end start
;*】*/