日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux c语言乘法口诀,shell 脚本实现乘法口诀表的两种方法——shell与C语言

發布時間:2025/3/21 linux 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux c语言乘法口诀,shell 脚本实现乘法口诀表的两种方法——shell与C语言 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

shell 腳本實現乘法口訣表的兩種方法——shell與C語言

話不多說直接給出代碼(執行c語言時沒有gcc編譯器會報錯的哦!):

1 #!/bin/bash

2 if [ $# -eq 0 ]

3 then

4 echo "welcome you!"

5 echo "this is a test with 2 methods to output arbitrarily mux table!"

6 else

7 echo "sorry you input invliad argc!"

8 echo "you input other argc before!"

9 exit 0

10 fi

11

12 while ((1))

13 do

14 echo "you can choose 'shell' 'gcc' or 'quit' command"

15 read -p "please input your choice:" choice

16

17 if [ $choice == "shell" ]

18 then

19 echo "will do show shell"

20 read -p "please input a num you want:" num

21 touch 6.sh

22 echo "" > 6.sh

23 echo '#!/bin/bash

24 for ((j=1;j<=$1;j++))

25 do

26 for((i=1;i<=j;i++))

27 do

28 echo -ne "$i*$j=$[$i*$j]\t"

29 done

30 echo -e "\r"

31 done

32 ' >> 6.sh

33 chmod 777 6.sh

34 cat 6.sh

35 source 6.sh $num

36 exit 0

37 elif [ $choice == "gcc" ]

38 then

39 echo "will do show c"

40 touch 6.c

41 echo "" > 6.c

42 echo '#include

43

44

45

46

47 int main(int argc,char **argv)

48 { if(argc<2)

49 perror("argc num is not correct!please do it again!");

50 printf("%s\n",argv[1]);

51 int num;

52 num=atoi(argv[1]);

53 int i,j;

54 for (j=1;j<=num;j++)

55 {

56 for(i=1;i<=j;i++)

57 {

58 printf("%d*%d=%d\t",i,j,i*j);

59 }

60 printf("\n");

61 }

62

63 return 0;

64 }' >> 6.c

65 cat 6.c

66 #判斷是否有安裝gcc編譯器

67 pName=$(rpm -qa | grep "$gcc")

68 if [ $? -eq 0]

69 then

70 echo "gcc had installed!"

71 else

72 echo "gcc is not installed!"

73 yum install -y gcc

74 fi

75 gcc -o 6 6.c

76 read -p "please input a number you want:" number

77 ./6 $number

78 exit 0

79 elif [ $choice == "quit" ]

80 then

81 exit 0

82 else

83 echo "you don't choose a correct choice!"

84 fi

85 done

總結

以上是生活随笔為你收集整理的linux c语言乘法口诀,shell 脚本实现乘法口诀表的两种方法——shell与C语言的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。