C++ Step Function Code Example
#include
// 定义一个名为'step'的函数 void step(int num) { for (int i = 1; i <= num; i++) { for (int j = 1; j <= i; j++) { std::cout << j << ' '; } std::cout << std::endl; } }
int main() { int num; std::cout << '请输入一个整数:'; std::cin >> num;
step(num);
return 0;
}
This program prompts the user to enter an integer. It then calls a function named 'step', passing the user input as an argument. The 'step' function uses two nested loops to print a staircase pattern of numbers. The outer loop controls the number of rows printed, while the inner loop controls the number of digits printed in each row.
原文地址: https://www.cveoy.top/t/topic/qlzJ 著作权归作者所有。请勿转载和采集!