当前位置:网站首页>[C language - zero foundation lesson 6] input and output sentence format and compound sentence
[C language - zero foundation lesson 6] input and output sentence format and compound sentence
2022-07-27 09:15:00 【Super Daxiong】
Preface
Blogger :Super Daxiong ( A cute new blogger )
C Language column :https://blog.csdn.net/m0_64857213/category_11678637.html
LeetCode special column :https://blog.csdn.net/m0_64857213/category_11691019.html
This issue is about C Language input and output statement related formats and compound statements , If there is any mistake, you are welcome to put forward your views .
Recommend one to my friends Study 、 Brush problem Website ?
Various Interview questions have everything that one expects to find , Brush questions until you feel soft !
All kinds of Internet Learning materials , The real interview questions of major factories start from Start learning from scratch , Help you cope easily Various interview questions , Come and enrich yourself !
Catalog
What is assignment 、 What is an assignment statement ?
example 1: String output as is
example 2. Specify width output
example 1: String output as is
example 2. Specify width output
Number and character assignment
Character input function :getchar
Character output function :putchar
Compound statements and empty statements
What is assignment 、 What is an assignment statement ?
In life, when we pour water into the cup, it is assignment , A cup is a container for storing things . stay C In language, variables are equivalent to a container used to store values , Different types of variables store different things . for example : The cup is filled with water 、 The picture frame is for photos 、 The clip of a pistol is used for loading bullets , Different things are packed in different containers .
C Used in language = To represent the assignment . Two equal signs == stay C Language means judgment .
for example :
int a=10C Language a set of statements must end with ;
Composition of assignment statement : Add ; Is the assignment statement .
for example :
int a=10;C In language ; The expression is a statement .
Data input statement
printf(“ character Format specification Escape character ”, Output item );
example 1: String output as is
int x = 123;
float y = 12.12;
printf("x=%d,y=%f\n",x,y);
printf("%d,%f", x, y);result :
x=123,y=12.120000
123,12.120000
example 2. Specify width output
int x = 123;
printf("x=%4d\n",x);
printf("x=%2d\n",x);result :
x=123
x=123
Be careful : first line x=123 There is a space here .
summary : If you specify the length > Fill in blank space for actual length , Positive numbers : Front edge patch , negative : Back filling .
float t=23.12345678;
printf("f=%7.2f\n",t);
printf("f=%10.6f\n",t);result :
f= 23.12 Two spaces
f=23.123457 A space
%n.mf:m Represents the total length of data ,n For decimal places
actual >n rounding
actual <n unchanged
Data input
scanf(“ character Format specification ”, Address );
int a, b, c;
// If you type 2 3 4
scanf("%d%d%d",&a, &b, &c );
printf("%d,%d,%d" ,a, b, c);result :2,3,4
& Is the address character
If there is no other symbol separation for integer data input , Use space or enter
example 1: String output as is
int a, b;
scanf("a=%d,b=%d",&a, &b );
printf("%d,%d\n" ,a, b);Input format :a=1,b=2
Otherwise, there will be an exception

example 2. Specify width output
int a, b, c;
scanf("%1d%2d%3d",&a,&b,&c);
printf("%d,%d,%d",a,b,c);Input format : 987654321
result :9,87,654
We can see that with the specified width, there is no need to enter the space
example 4: Real data input
float t;
scanf("%2.5f",&t);Bear in mind : Real data cannot specify decimal digits .
Character input and output
char a, b;
scanf("%c%c",&a,&b);
printf("%c,%c",a,b);Input format : b
result : ,b
Spaces are also counted as strings
Number and character assignment
char a;
int b;
scanf("%d%c",&a,&b);
printf("%d,%c",a,b);Input format : 3a
result :3,a
Input format : 3a
result :3,
Input format : 10a
result :10,a
Be careful :%c No space before , Character refers to a
Character input function :getchar()
char a;
a=getchar();
printf("%c",a);Input format : a
result :a
Character output function :putchar()
char a;
a=getchar();
putchar(a);Compound statements and empty statements
A compound statement is a statement formed by multiple statements { }
{ } It's called a statement block , stay {} What's inside becomes a sentence .
A statement block contains multiple statements .
{
int a;
int b;
int c;
int d;
}Empty statement
;Only semicolons “;” A statement that is composed of is called an empty statement , The system will do nothing until it is executed , And then go on !
Empty statements are legal .
Recommend one to my friends Study 、 Brush problem Website ?
Various Interview questions have everything that one expects to find , Brush questions until you feel soft !
All kinds of Internet Learning materials , The real interview questions of major factories start from Start learning from scratch , Help you cope easily Various interview questions , Come and enrich yourself !Click on the I Start registration Study 、 Brush problem
边栏推荐
- js call和apply
- 【进程间通信IPC】- 信号量的学习
- Can "Gulangyu yuancosmos" become an "upgraded sample" of China's cultural tourism industry
- NPM and yarn update dependent packages
- Flex layout (actual Xiaomi official website)
- 500 error reporting
- Interface test tool -postman usage details
- 【每日算法Day 94】经典面试题:机器人的运动范围
- 苹果降价600元,对本就溃败的国产旗舰手机几乎是毁灭性打击
- 巴比特 | 元宇宙每日必读:广州南沙发布“元宇宙九条”措施,平台最高可获得2亿元资金支持...
猜你喜欢
![[acl2020] a novel method of component syntax tree serialization](/img/24/b8ec489966f7b1deef82b2eefa4d1b.png)
[acl2020] a novel method of component syntax tree serialization

CUDA programming-02: first knowledge of CUDA Programming

How to optimize the deep learning model to improve the reasoning speed

Babbitt | yuan universe daily must read: Guangzhou Nansha released the "Yuan universe nine" measures, and the platform can obtain up to 200million yuan of financial support

500 error reporting

5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises

Deep understanding of Kalman filter (1): background knowledge

"Weilai Cup" 2022 Niuke summer multi school training camp 1

8 kinds of visual transformer finishing (Part 2)

PVT's spatial reduction attention (SRA)
随机推荐
Save Xiaoyi from Netease written test -- a typical application of Manhattan distance
JS call and apply
Interface test tool - JMeter pressure test use
Data interaction based on restful pages
Easy language programming: allow the screen reading software to obtain the text of the label control
Built in method of tensorflow model training and evaluation
Tensorflow package tf.keras module construction and training deep learning model
Wechat applet 5 - foundation strengthening (not finished)
Nut joke based on arkui ETS
Restful
Tensorflow loss function
网易笔试之解救小易——曼哈顿距离的典型应用
5g failed to stimulate the development of the industry, which disappointed not only operators, but also mobile phone enterprises
Apple cut its price by 600 yuan, which was almost a devastating blow to the collapse of its domestic flagship mobile phone
Explanation of common basic controls for C # form application (suitable for Mengxin)
Deep understanding of Kalman filter (1): background knowledge
Matlab drawing skills and examples: stackedplot
Music experience ceiling! Emotional design details of 14 Netease cloud music
MySQL basic knowledge learning (I)
500 error reporting