<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          練習35 指針數(shù)組作main函數(shù)的參數(shù)

          共 891字,需瀏覽 2分鐘

           ·

          2021-07-21 05:26

          點擊藍字

          關注我們

          DRAGON BOAT FESTIVAL




          練習35


          01 要求:

          使用命令行參數(shù)向文件中輸入隨機數(shù)據(jù)

          例如命令行中輸入:


          .exe data.txt 0 100 5

          則可在data.txt 文件中獲得5個[0,100]之間的數(shù)據(jù)

          其中源.exe為源程序生成的可執(zhí)行文件


          02 程序示例如下:

          /*使用命令行參數(shù)向文件中輸入隨機數(shù)據(jù)

          運行:源.exe data.txt 0 100 5

          運行文件 數(shù)據(jù)文件 隨機數(shù)最小值 隨機數(shù)最大值 n個隨機數(shù)

          */


          #include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>#include<time.h>
          int main(int argc, char *argv[]){ FILE *fp1; fp1 = fopen(argv[1], "w");
          int min = atoi(argv[2]); int max = atoi(argv[3]); int n = atoi(argv[4]); int data;
          srand((unsigned)time(NULL)); //初始化隨機數(shù) for (int i = 0; i < n; i++){ data = rand() % (max - min + 1) + min; fprintf(fp1, "%d\n", data); //向所建文件寫一字符串 }


          return 0;}


          03:輸出:

          輸入的命令行參數(shù)為:

          .exe data.txt 0 100 5

          結(jié)果為

          7

          78

          55

          18

          90


          球分享

          球點贊

          球在看

          瀏覽 50
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  一道本高清一二三区视频 | 九九九九精美视频 | 国产无码小电影 | 国产无码激情在线 | 欧美成人免费在线 |