当前位置:网站首页>电子协会 C语言 1级 28 、字符菱形
电子协会 C语言 1级 28 、字符菱形
2022-06-25 04:05:00 【dllglvzhenfeng】
电子协会 C语言 1级 28 、字符菱形
C语言代码:
/*
电子协会 C语言 1级 28 、字符菱形
http://noi.openjudge.cn/ch0101/09/
给定一个字符,用它构造一个对角线长 5 个字符,倾斜放置的菱形。
输入:输入只有一行, 包含一个字符。
输出
该字符构成的菱形。
样例输入
*
样例输出
*
***
*****
***
*
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
//给定一个字符,
scanf("%c",&ch);
//用它构造一个对角线长5个字符,倾斜放置的菱形。
printf(" %c\n",ch);
printf(" %c%c%c\n",ch,ch,ch);
printf("%c%c%c%c%c\n",ch,ch,ch,ch,ch);
printf(" %c%c%c\n",ch,ch,ch);
printf(" %c\n",ch);
return 0;
}C++代码:
/*
电子协会 C语言 1级 28 、字符菱形
http://noi.openjudge.cn/ch0101/09/
给定一个字符,用它构造一个对角线长 5 个字符,倾斜放置的菱形。
输入:输入只有一行, 包含一个字符。
输出
该字符构成的菱形。
样例输入
*
样例输出
*
***
*****
***
*
*/
#include<iostream> //使用cin,cout,须调用iostream库
using namespace std;
int main()
{
char a; //定义字符变量,
cin>>a; //输入给定一个字符
cout<<" "<<a<<endl; //输出1个字符,先输出2个空格
cout<<" "<<a<<a<<a<<endl; //输出3个字符,先输出1个空格
cout<<a<<a<<a<<a<<a<<endl; //输出5个字符
cout<<" "<<a<<a<<a<<endl; //输出3个字符,先输出1个空格
cout<<" "<<a<<endl; //输出1个字符,先输出2个空格
return 0; //结束程序
}python3代码:
a = input()
print(' '+a+' ')
print(' '+a+a+a+' ')
print(a+a+a+a+a)
print(' '+a+a+a+' ')
print(' '+a+' ')边栏推荐
- 基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
- CSRF (Cross Site Request Forgery) &ssrf (server request forgery) (IV)
- WPF uses Maui's self drawing logic
- What if win11 Bluetooth fails to connect? Solution of win11 Bluetooth unable to connect
- Use serialize in egg to read and write split tables
- Laravel Aurora push
- What if the desktop computer is not connected to WiFi
- A summary of the experiment of continue and break in C language
- Google Earth engine (GEE) - Global jrc/gsw1_ 1 / batch download of yearlyhistory dataset (China region)
- 基于SSH实现的学生成绩管理系统
猜你喜欢

How to use the Magic pig system reinstallation master

WPF uses Maui's self drawing logic

buuctf web

本轮压力测试下,DeFi协议们表现如何?

Kotlin compose listens to the soft keyboard and clicks enter to submit the event

EL & JSTL (XIII)

Eyeshot 2022 Released
Triangle class (construction and deconstruction)

Why does the SQL statement hit the index faster than it does not?

What is Ethernet and how to connect the computer
随机推荐
Filter & listener (XIV)
Visual studio 2022 interface beautification tutorial
Create an environment for new projects
CTFHub-rce
Opensea PHP development kit
parallel recovery slave next change & parallel recovery push change
Response (XI)
Database overview
ORA-00800: soft external error
In Net 6 using dotnet format formatting code
Database query optimization method
Object creation and invocation code example
Introduction to the hardest core PWN in the whole network_ Graphic analysis
Kotlin compose perfect todo project surface rendering background and shadow
Detailed summary of position positioning
Wechat applet new version prompt update
Difference between asemi high power FET and triode
Penetration test - directory traversal vulnerability
Write shell script error summary
parallel recovery slave next change & parallel recovery push change