题目描述
用 *
构造一个对角线长 $5$ 个字符,倾斜放置的菱形。
输入格式
没有输入要求。
输出格式
如样例所示。用 *
构成的菱形。
样例 #1
样例输入 #1
样例输出 #1
*
***
*****
***
*
题解
C
#include <stdio.h>
int main()
{
printf(
" *\n"
" ***\n"
"*****\n"
" ***\n"
" *\n");
return 0;
}
知识点
printf( ) 函数支持多行文本输出,示例如上
C++
#include <iostream>
using namespace std;
int main()
{
cout<<" *"<<endl;
cout<<" ***"<<endl;
cout<<"*****"<<endl;
cout<<" ***"<<endl;
cout<<" *"<<endl;
return 0;
}
知识点
C++兼容C语言,可以像上面C语言一样编写,这里给出另外一种思路
Python
print(" *")
print(" ***")
print("*****")
print(" ***")
print(" *")
注意:Python中print( ) 函数自带换行
题目版权归 洛谷(www.luogu.com.cn)所有,本贴只讨论题目解法
题目链接:https://www.luogu.com.cn/problem/B2025