把以下程序中的print()函数改写为等价的递归函数。
#include <iostream> using namespace std; void print( int w ) { for( int i = 1; i <= w; i ++ ) { for( int j = 1; j <= i; j ++ ) cout << i << " "; cout << endl; } } int main() { print( 5 ); }
程序运行结果:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5