问题是:
我做了什么:
我分别使用了 2 1 0 代替了 + - ' '。这道题必须通过函数来完成。
但是,这些与给出的输出不匹配。我哪里出错了?
最佳答案
我们初学者应该互相帮助。:)
给你。该代码是用 C++ 编写的。所以你需要研究它并自己用 C 重写它。
#include <iostream>
int main()
{
while ( true )
{
std::cout << "Input the number of elements : ";
unsigned int n;
if ( not ( std::cin >> n ) or ( n == 0 ) ) break;
std::cout << "Input the size of each element : ";
unsigned int m;
if ( not ( std::cin >> m ) or ( m == 0 ) ) break;
std::cout << '\n';
for ( unsigned int i = 0; i < m + 2; i++ )
{
char c1 = i == 0 || i == m + 1 ? '+' : '|';
char c2 = i == 0 || i == m + 1 ? '-' : ' ';
for ( unsigned int j = 0; j < n + m * ( n - 1 ); j++ )
{
std::cout << ( j % (m + 1) == 0 ? c1 : c2 );
}
std::cout << '\n';
}
std::cout << std::endl;
}
return 0;
}
程序输出可能如下所示
Input the number of elements : 10
Input the size of each element : 3
+---+---+---+---+---+---+---+---+---+
| | | | | | | | | |
| | | | | | | | | |
| | | | | | | | | |
+---+---+---+---+---+---+---+---+---+
Input the number of elements : 0
关于c - 通过函数的模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41663575/