--条件语句:
--例子:
--求三个数的最大值:
maxThree :: Int -> Int -> Int -> Int
maxThree x y z
| x>=y&&x>=z = x
| y>=z = y
| otherwise = z
--求两个数的较小的数:
minTwo :: Int -> Int -> Int
minTwo a b = if a >= b then b else a
--将一个数加倍
double :: Int -> Int
double a = a*2
--求出两个数中更大的那个
mymax::Int->Int->Int
mymax a b
| a>= b = a
| otherwise = b
prop_Max :: Int -> Int -> Bool
prop_Max x y = x<=max x y&&y <= max x y --如果性质总是返回true,那么说明规格是满足的
maxThree :: Int -> Int -> Int -> Int
maxThree x y z
| x>=y&&x>=z = x
| y>=z = y
| otherwise = z
--求出两个数中更小的数字
minTwo :: Int -> Int -> Int
minTwo a b = if a >= b then b else a
--求阶乘
factorial :: Int -> Int
factorial 0 = 1
factorial n
|n>0 = factorial(n-1)*n
--求幂
power1 :: Int -> Int -> Int
power1 x n = x^n
power2 :: Int -> Int -> Int
power2 x 0 = 1
power2 x n = power2 x (n-1) *x
power3 :: Int -> Int -> Int
power3 x 0 = 1 --不要漏掉递归基
power3 x n --x^(2*n) == (x*x)^n;x^(2*n+1) == (x*x)^n*x
| n`mod`2 == 0 = power3(x*x)(n`div`2)
| n`mod`2 == 1 = power3(x*x)(n`div`2)*x --这个递归的速度更快
--判断是否为偶数
isEven :: Int -> Bool
isEven a = a`mod`2==0
--判断是否为偶数
isOdd :: Int -> Bool
isOdd a = a`mod`2==1
--判断三数字是否都不一样
threeDifferent :: Int -> Int -> Int -> Bool
threeDifferent a b c
| (a==b)||(a==c)||b==c = False
| otherwise = True