使用 * 打印半金字塔的程序
C++
xxxxxxxxxx
using namespace std;
int main()
{
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for(int i = 1; i <= rows; ++i)
{
for(int j = 1; j <= i; ++j)
{
cout << "* ";
}
cout << "\n";
}
return 0;
}
Enter number of rows: 5 * * * * * * * * * * * * * * *
使用数字打印半金字塔 a 的程序
C++
xxxxxxxxxx
using namespace std;
int main()
{
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for(int i = 1; i <= rows; ++i)
{
for(int j = 1; j <= i; ++j)
{
cout << j << " ";
}
cout << "\n";
}
return 0;
}
Enter number of rows: 5 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
使用字母打印半金字塔的程序
A B B C C C D D D D E E E E E
C++
xxxxxxxxxx
using namespace std;
int main()
{
char input, alphabet = 'A';
cout << "Enter the uppercase character you want to print in the last row: ";
cin >> input;
for(int i = 1; i <= (input-'A'+1); ++i)
{
for(int j = 1; j <= i; ++j)
{
cout << alphabet << " ";
}
++alphabet;
cout << endl;
}
return 0;
}
使用 * 的倒半金字塔
C++
xxxxxxxxxx
using namespace std;
int main()
{
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for(int i = rows; i >= 1; --i)
{
for(int j = 1; j <= i; ++j)
{
cout << "* ";
}
cout << endl;
}
return 0;
}
Enter number of rows: 5 * * * * * * * * * * * * * * *
使用数字的倒半金字塔
C++
xxxxxxxxxx
using namespace std;
int main()
{
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for(int i = rows; i >= 1; --i)
{
for(int j = 1; j <= i; ++j)
{
cout << j << " ";
}
cout << endl;
}
return 0;
}
Enter number of rows: 5 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
Linux - 如何安装 anc-api-tools
Linux - 如何安装 curvedns
Python - 检查数字是正数、负数还是 0
Linux - 如何安装 zenmap
C - 计算整数中的位数
C++ - 检查闰年
JavaScript - 检查字符串是否以某些字符开头和结尾
C++ - 检查一个数字是否是素数
C - 使用动态内存分配查找最大数
Kotlin - 将数字四舍五入到 n 个小数位
Linux - 如何安装 xbitmaps
Linux - 如何安装 zstd
Kotlin - 反转数字
Java - 反转数字
Python - 编写 Excel (XLSX) 文件
C++ - 求商和余数
Linux - 如何安装 zfs-test
Java - 创建金字塔和图案
We have been online since 2021 and 1 millions of people around the globe have visited our website since then
More visitors every month