第四周作业

1. 计算 100 以内所有能被 3 整除的整数之和

              #!/bin/bash

              let sum=0

              for i in {1..100};do

              if [ $[$i%3] -eq 0 ];then

              sum=$[$sum+$i]

               fi

              done

              echo "sum=$sum"
2. 编写脚本,求 100 以内所有正奇数之和

              #!/bin/bash

              sum=0

              for((i=1;i<100;i=i+2));do

              let sum=sum+i

              done

              echo $sum

    
3. 随机生成 10 以内的数字,实现猜字游戏,提示比较大或小,相等则退出

             #!/bin/bash


             NUM=$[RANDOM%10]


             while read -p "输入0-9之间的数字:" SU ;do


             if [ $SU -eq $NUM ];then

            echo "恭喜你猜对了!"

            break

            elif [ $SU -gt $NUM ];then

             echo"数字太大了,重新猜!"

            else


            echo "数字太小了,重新猜!"

             fi

            done


4. 编写函数,实现两个数字做为参数,返回最大值

            #include <stdio.h>

            int onetwo(int a,int b);

            int main()

            {

               int a;

               int b;

               while(~scanf("%d %d",&a,&b))

               {

                   onetwo(a,b);

                   printf("%d\n",onetwo(a,b));

               }

               return 0;

            }

            int onetwo(int a,int b)

             {

                 if(a>b)

                    return a;

                 else

                    return b;

             }
5. 编写一个httpd安装脚本

#!/bin/bash

#下载源码包

ANZHUANG_DIR=/usr/local

wget https://downloads.apache.org/httpd/httpd-2.4.43.tar.gz

#安装依赖包

yum install -y gcc make apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config 

#解压源码包

tar xf /httpd-2.4.43.tar.gz -C $ANZHUANG_DIR

cd $ANZHUANG_DIR/httpd-2.4.43

#编译安装

./configure --prefix=$ANZHUANG_DIR

make && make install

#启动httpd服务

apachectl start

 

posted @ 2020-06-21 14:48  guobang  阅读(136)  评论(0编辑  收藏  举报