标签:str ber stream 不能 out amp i++ int 习题
刷题ing,碰到这么一个经典习题。知道是个for循环,想着能不能用while做出来,越想越困,算了,还是for吧。。。
#include <stdio.h>
#include "stdafx.h"
#include <iostream>
#include<time.h>
using std::cin;
using std::cout;
int main() {
int n;
cout << "Please enter a number less than 21:" << std::endl;
cin >> n;
if (0 <= n && n <= 20) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
cout << " ";
}
for (int k = i; k <= 2 * n - i; k++) {
cout << "*";
}
cout << std::endl;
}
}
else
cout << "The number is wrong!!!" << std::endl;
}
有些头文件是做别的题遗留下来的,请勿见怪~~
标签:str ber stream 不能 out amp i++ int 习题
原文地址:https://www.cnblogs.com/NK-007/p/9168441.html