发几个简单的算法
mfp吧
全部回复
仅看楼主
level 5
求两数的比值
function bi(a,b)
variable aa=a , bb=b , c=0 , d=0 , hh=true
if(a==b)
print("两数之比为1:1")
hh=false
endif
while(hh)
if(a>b)
c=mod(a,b)
if(c==0)
d=b
hh=false
print("两数之比为"+aa/d+":"+bb/d)
else
a=c
endif
else
c=mod(b,a)
if(c==0)
d=a
hh=false
print("两数之比为"+aa/d+":"+bb/d)
else
b=c
endif
endif
loop
endf
2016年08月23日 17点08分 1
level 5
用求根公式求一元二次方程的解
function yyec(a,b,c)
variable x=0,y=0
if((b**2-4*a*c)<0)
print("此方程无解")
else
if((b**2-4*a*c)==0)
x=-b/(2*a)
print("x的值为"+x)
else
x=(-b+(b**2-4*a*c)**0.5)/(2*a)
y=(-b-(b**2-4*a*c)**0.5)/(2*a)
print("x1的值为"+x+"\n")
print("x2的值为"+y+"\n")
endif
endif
endf
2016年08月23日 17点08分 2
求a.X²+b.X+c=0的根,用solve算的结果无论何时都是得出两个解(两个不同虚数解,或两个一样的解,或者两个不同实数解)
2016年08月23日 17点08分
a=3,b=4,c=3,根roots([3,4,3])
2016年08月23日 22点08分
@😄二师兄他师哥 还是得出两个虚数根,需要求虚数根的时候才用,现在大部分学生只需要求实数根
2016年08月24日 01点08分
level 5
求排列的值
function aa(m,n)
variable a=1,b=1
for variable g=1 to n step 1
a=a*g
next
for variable h=1 to (n-m) step 1
b=b*h
next
return a/b
endf
2016年08月23日 17点08分 3
m≤n
2016年08月23日 17点08分
nPr(3,2)
2016年08月23日 22点08分
@😄二师兄他师哥 有了吗[汗]没看到
2016年08月24日 01点08分
level 5
求组合的值
function cc(m,n)
variable a=1,b=1,c=1
for variable g=1 to n step 1
a=a*g
next
for variable h=1 to m step 1
b=b*h
next
for variable j=1 to (n-m) step 1
c=c*j
next
return a/(b*c)
endf
2016年08月23日 17点08分 4
m≤n
2016年08月23日 17点08分
function cc(m,n) return nCr(n,m) endf n>=m
2016年08月23日 22点08分
@😄二师兄他师哥 这个也有了[黑线]尴尬了
2016年08月24日 01点08分
level 13
[疑问]a!=0⇒bi(0,a)==0
bi(a,0)⇒false
2016年08月23日 22点08分 6
variable x if(image(x,0)!=0) print("x为虚数") else print("x为实数") endif bi(2*i,2*i)=1 [疑问]bi(12*i,3*i)⇒false
2016年08月23日 22点08分
我是想用非的,但是mfp逻辑函数里没有非,我还以为这个语言本身就没有非,来这里问过一次,没人理我
2016年08月24日 01点08分
@😄二师兄他师哥 用的辗转相除法[汗]算不了虚数,我还没你们那么厉害[不高兴]
2016年08月24日 01点08分
level 1
mfp逻辑非是!
2016年08月25日 05点08分 7
1