代码方式的几道题

1.输出10行我爱中国

#!/bin/bash

#auther:nora

#data:2024/10/17

#main:输出十行我爱中国

#welcome chap1.sh

for  ((i=1;i<=10;i++))

do

        echo "我爱中国!"

done

exit 0

2. 输出倒三角

#!/bin/bash

#auther:nora

#data:2024/10/17

#main:shuchufuwamingcheng

#welcome chap1.sh

for ((i=5;i>=0;i--))

do

jCon=$((5-$i))

for ((j=1;j<=jCon;j++))

do

echo -n " "

done

kCon=$((2*$i-1))

for ((k=1;k<=$kCon;k++))

do

echo -n "*"

done

echo " "

done

exit 0

3.  计算100以内所有偶数的和

#!/bin/bash

#auther:nora

#data:2024/10/17

#main:shuchufuwamingcheng

#welcome chap1.sh

sum=0;

n=2;

while [[ $n -le 100 ]]

do

sum=$(($sum+$n))

n=$(($n+2))

done

echo "the sum is:" $sum

exit 0

4. 百钱买白鸡,5文钱一只公鸡,4文钱一只母鸡,1文钱可以买3只小鸡,要求用100文钱买100只鸡

#!/bin/bash

#auther:nora

#data:2024/10/17

#main:jisuan100wenqianmai100zhiji

#welcome chap1.sh

for x in {0..20}; do

for y in {0..25}; do

z=$((100 - x - y))

if [ $((15*x +12*y +z)) -eq 300 ] && [ $((x + y + z)) -eq 100 ];

then

echo "公鸡: $x只,母鸡: $y只,小鸡: $z只"

fi

done

done

exit 0

你可能感兴趣的:(chrome,前端)