编写脚本程序mul-3.sh(for与while结合),实现99乘法表
时间: 2024-02-27 09:56:00 浏览: 20
好的,以下是mul-3.sh的代码实现:
```bash
#!/bin/bash
# 使用for循环实现
echo "使用for循环实现:"
for ((i=1;i<=9;i++));
do
for ((j=1;j<=i;j++));
do
let "mul=i*j"
echo -n "$i*$j=$mul "
done
echo ""
done
# 使用while循环实现
echo "使用while循环实现:"
i=1
while [ $i -le 9 ]
do
j=1
while [ $j -le $i ]
do
let "mul=i*j"
echo -n "$i*$j=$mul "
let "j++"
done
echo ""
let "i++"
done
```
运行脚本程序,即可得到99乘法表的输出结果。
相关问题
: Use this idea to write a procedure invert-unit-series that computes 1/S for a unit power series S. You will need to use mul-series. To test your procedure, invert the series S1 (from problem 1) and show that you get the series 1 - x. (Convince yourse
lf that this is the correct answer.)
Here is a possible implementation of the invert-unit-series procedure:
```
(define (invert-unit-series S)
(let ((one-series (cons 1 (stream)))
(reciprocal-series (cons 1 (mul-series (stream-map -1 S) reciprocal-series))))
reciprocal-series))
```
The procedure first defines a series of all ones, which is used as the starting point for the reciprocal series. It then uses the mul-series procedure to compute the product of -1 and each coefficient of the input series S, and recursively applies this operation to the reciprocal series until it converges to the desired result.
To test this procedure, we can apply it to the S1 series from problem 1:
```
(define S1 (cons 1 (stream-map -1/2 (add-series (stream-map square integers) (cons 1 (stream))))))
(define S1-inverse (invert-unit-series S1))
(stream-take 10 S1-inverse)
; => (1 -1 1 -1 1 -1 1 -1 1 -1)
```
As expected, the coefficients alternate between 1 and -1, which corresponds to the series 1 - x. Therefore, we can be confident that the invert-unit-series procedure is correct.
编写一个Java程序在屏幕上输出1!+2!+3! -...+10!的和
以下是两种Java程序在屏幕上输出1!+2!+3!+...+10!的和的例子:
1. 引用中的程序:
```java
public static int jc10(){
int jc=1;
int num=0;
for(int i=1;i<=10;i++){
jc=1;
for(int j=;j<=i;j++){
jc*=j;
}
num+=jc;
}
return num;
}
System.out.println("1!+2+3!+...+10!的和为:"+jc10());
```
2. 引用中的程序:
```java
int i, j, mul, sum = 0;
for (i = 1; i <= 10; i++) {
mul = 1;
for (j = 1; j <= i; j++) {
mul = mul * j;
}
sum = sum + mul;
}
System.out.println("1!+2!+3!+...+10!的和为:" + sum);
```