I want to get the product (ie multiplication, but only doing successive addition).
So far I have this code.
#!/bin/bash
echo "Introduce un dato"
read A
echo "Introduce el segundo dato"
read B
for (( C=1; C<$B; C++ ))
do
C=`expr $C + $B`
echo "El producto es: $C"
done
I don't know if it would be necessary to make another loop, I had also thought about whether a value could be increased in the FOR, let me explain, I know that variables can be increased with ++, but it is possible to do this by adding another variable. So maybe if you could do the successive sums. Thanks.
You can use the increment operator
+=
, plus you can do this inside the double parentheses ((( expresion ))
) which is similar toexpr
(only I understand that the latter is archaic).Your code could look like this:
Resulting its execution: