Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.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++ 需要3个单独的输出 想要的输出:_C++_For Loop_While Loop_Do Loops - Fatal编程技术网

C++ 需要3个单独的输出 想要的输出:

C++ 需要3个单独的输出 想要的输出:,c++,for-loop,while-loop,do-loops,C++,For Loop,While Loop,Do Loops,如何从每个循环中获得输出?1)您应该将每个循环开头的列初始化为0 2) 在while和do循环中,在进入内部循环之前,将行初始化为0 最后的输出3是由于do while循环中有一个入口。您可以让for循环保持原样: 0 0, 0 1, 0 2 1 0, 1 1, 1 2 2 0, 2 1, 2 2 0 0, 0 1, 0 2 1 0, 1 1, 1 2 2 0, 2 1, 2 2 0 0, 0 1, 0 2 1 0, 1 1, 1 2 2 0, 2 1, 2 2 0 0, 0 1, 0 2

如何从每个循环中获得输出?

1)您应该将每个循环开头的
列初始化为
0

2) 在
while
do
循环中,在进入内部循环之前,将
初始化为
0


最后的输出
3
是由于
do while
循环中有一个入口。

您可以让
for
循环保持原样:

0 0, 0 1, 0 2
1 0, 1 1, 1 2
2 0, 2 1, 2 2

0 0, 0 1, 0 2
1 0, 1 1, 1 2
2 0, 2 1, 2 2

0 0, 0 1, 0 2
1 0, 1 1, 1 2
2 0, 2 1, 2 2
0 0, 0 1, 0 2
1 0, 1 1, 1 2
2 0, 2 1, 2 2
3 3
0 0, 0 1, 0 2
1 0, 1 1, 1 2
2 0, 2 1, 2 2

0 0, 0 1, 0 2
1 0, 1 1, 1 2
2 0, 2 1, 2 2

0 0, 0 1, 0 2
1 0, 1 1, 1 2
2 0, 2 1, 2 2
    for (; column < colCount; column++){
        for(row = 0; row <= (rowCount - 1); row++){
            std::cout << column << " " << row;
            if(row < (rowCount - 1))
                std::cout << ", ";
        }
        std::cout << std::endl;
    }
#include <iostream>

int main ()
{
    int row, column = 0, colCount = 3, rowCount = 3;

    //for loop
    for (column; column < colCount; column++){
        for(row = 0; row <= (rowCount - 1); row++){
            std::cout << column << " " << row;
            if(row < (rowCount - 1))
                std::cout << ", ";
        }
        std::cout << std::endl;
    }
    std::cout<<std::endl;
    //while loop
    column = 0;
    row = 0;
    while(column < rowCount){
        while(row < rowCount){
            std::cout << column << " "<< row;
            if(row < (rowCount - 1))
                std::cout << ", ";
            row++;          
        }
        std::cout << std::endl;   
        column += 1;
        row = 0;
    }
    //do while loop
    std::cout<<std::endl;
    column = 0;
    row = 0;
    do{
        do{
            std::cout << column << " "<< row;
            if(row < (rowCount - 1))
                std::cout << ", ";
            row++;  
        }while(row < rowCount);
        std::cout << std::endl;
        column +=1;
        row = 0;
    }while(column < colCount);
    return 0;
}