如何制作垂直之字形?那会生成随机字母?作为一个初学者,我不明白

问题描述 投票:0回答:0

这是我需要做的基础代码行。

    1 #include <stdio.h>
    2 #include <stdlib.h>
    3 #include <time.h>
    4 #include <unistd.h>
    5
    6
    7
    8 int main() {
    9
    10     int num;
    11     float test;
    12     printf("Hello World\n");
    13
    14     srand(time(NULL));
    15
    16     for(int x = 0; x<10; x++){
    17     //generate number here:
    18 //  num = (rand() % (higher - lower + 1)) + lower;
    19     num = (rand() % (25-13 +1)) + 13;
    20
    21     printf("Number is %d\n", num);
    22     usleep(100000);
    23 }
    24     const int numRows = 6;
    25 const int numCols = 21;
    26 for (int row = 0; row < numRows; ++row)
    27 {
    28     for (int col = 0; col < numCols; ++col)
    29     {
    30         if (col == row)
    31         {
    32             printf("X");
    33         }
    34         else
    35         {
    36             printf(" ");
    37         }
    38     }
    39     printf("\n");
    40 }
    41
    42
    43
    44     return 0;
    45 }

这是我想要的结果:

enter image description here

是否可以输入随机生成的数字而不是“*”?我需要包括睡眠功能和随机生成的数字,但我坚持如何制作垂直之字形。

有人有任何指示/解决方案吗?

我创建了生成随机数的代码并使用了睡眠函数。我也开始了锯齿形图案,但很难垂直继续它。

c zigzag
© www.soinside.com 2019 - 2024. All rights reserved.