Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 垂直直方图打印问题_C_Histogram - Fatal编程技术网

C 垂直直方图打印问题

C 垂直直方图打印问题,c,histogram,C,Histogram,我希望它像: | |*| //Prints "width" as height. | |*| | |*| |*|*| |*|*| |*|*|..... 有没有办法用我的代码实现这个输出?对不起,如果我不清楚,我不擅长英语。我也是C编程的新手,仍在努力理解它的行为。谢谢大家! 此代码按您所说的那样工作 | | | | | | | |***| |***|***|..... 1 2 for(int a=0;a

我希望它像:

  | |*|         //Prints "width" as height.
  | |*|
  | |*|
  |*|*|
  |*|*|
  |*|*|.....

有没有办法用我的代码实现这个输出?对不起,如果我不清楚,我不擅长英语。我也是C编程的新手,仍在努力理解它的行为。谢谢大家!

此代码按您所说的那样工作

  |   |   |
  |   |   |
  |   |***|
  |***|***|.....
    1   2
for(int a=0;a<9;a++){
如果(hm=0;i--){
printf(“|”);
//对于(int t=0;ti){
for(int t=0;t你的问题是什么?你也应该正确地缩进你的代码,让它可读。OKI我在NETBeBes中自动格式化我的代码,但是因为我正在使用DEV C++,所以我找不到一个快捷方式来格式化我的代码。这种格式对我来说更容易理解。
  |   |   |
  |   |   |
  |   |***|
  |***|***|.....
    1   2
for (int a = 0; a < 9; a++) {
    if (hm <= arr[a]) //hm is Maximum number in array for height of a column.
        hm = arr[a];
}
for (int i = hm; i >= 0; i--) {
    printf("|");
    //for(int t = 0; t < width; t++){ //Width is where i got in trouble.
        //printf("|");
        for (int a = 0; a < 9; ++a) {
            if (arr[a] > i) {
                for(int t = 0; t < width; t++){ //Here where you should have added the for loop
                    printf("*");
                }
                //printf("*|");
                printf("|");
            }
            else{
                for(int t = 0; t < width; t++){ //Here where you should have added the for loop
                    printf(" ");
                }
                printf("|");
                //printf(" |");
            }
        }
        printf("\n");
    //}
}
return 0;