当前位置:网站首页>C - sequential structure
C - sequential structure
2022-07-05 19:49:00 【Can't learn java】
Sequential structure
1、 Assignment statement
- Add
A semicolon
This is the assignment statement .
2、 Data output
Output the characters as they are
Specify width output : If the length is not enough, fill in the space to the left
%m.nf: m— Represents the total length of data ,n For decimal places ,n For decimal places
- Actual length >n( rounding )
- Actual length <n( Zero on the right )
int a=234; printf("a=%4d\n",a); printf("a=%2d\n",a); Output results : 234 234 float f=24.3567; printf("f=%7.2f\n",f); printf("f=%10.5f\n",f); Output results : 24.36 24.35670
The number of output items is greater than the number of output formats ,
Redundant items are not output
The maximum value of the integer data range +1 Get the smallest range value , The minimum value of the range -1 Get the maximum value of the range
3、 Data input
& Address fetch
Operator
SpacerThere is no limit to the quantity
, alsoIt can be mixed up
If there is no other character separator for integer data input , Separate with spaces or carriage returnsThe input item must be the address of the variable
example 1:
int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("%d,%d,%d\n",a,b,c); Here we are a assignment 1,b assignment 2,c assignment 3, be Input writing :1 2 3 Output results :1,2,3
example 2: Specify the width of the input data
int a,b,c; scanf("%2d%3d%4d",&a,&b,&c); printf("%d,%d,%d\n",a,b,c); Input from keyboard :1234567890 Output results :12,345,6789
example 3: Real data input , When inputting real data ,
Cannot specify decimal
digitfloat f; scanf("%7.2f",&f); // Error can only specify width , You cannot specify the number of decimal places
example 4: Character input and output ,char Type accepts only one character ,%c There must be no blank space before
char c1,c2; scanf("%c%c",&c1,&c2) printf("%c,%c\n",c1,c2); Now to c1 The assignment character A,c2 The assignment character B Input :AB Output :A,B
Character input function :
getchar()
Character output function :
putchar(ch)
4、 Compound statements and empty statements
4.1、 Compound statement
form :{ }
{ a=2;b=3;c=a+b;}
4.2、 Empty statement
- form :
;
5、 Program instance
Enter two integers a and b, Exchange its value and output
example 1:
int a,b,t; scanf("%d%d",&a,&b); t=a; a=b; b=t; printf("%d,%d\n",a,b);
example 2:
int a,b; scanf("%d%d",&a,&b); a=a+b; b=a-b; a=a-b; printf("%d,%d\n",a,b);
边栏推荐
- PHP利用ueditor实现上传图片添加水印
- 四万字长文说operator new & operator delete
- 挖财钱堂教育靠谱安全吗?
- The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
- 建立自己的网站(16)
- Fundamentals of shell programming (Part 8: branch statements -case in)
- What are general items
- Is it safe for Guohai Securities to open an account online?
- 【无标题】
- JAD installation, configuration and integration idea
猜你喜欢
How to choose the notion productivity tools? Comparison and evaluation of notion, flowus and WOLAI
Redis cluster simulated message queue
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
Fuzor 2020軟件安裝包下載及安裝教程
Tutoriel de téléchargement et d'installation du progiciel fuzor 2020
毫米波雷达人体感应器,智能感知静止存在,人体存在检测应用
MMO project learning 1: preheating
[AI framework basic technology] automatic derivation mechanism (autograd)
Android面试,android音视频开发
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
随机推荐
完爆面试官,一线互联网企业高级Android工程师面试题大全
Summer Challenge database Xueba notes, quick review of exams / interviews~
IBM has laid off 40 + year-old employees in a large area. Mastering these ten search skills will improve your work efficiency ten times
测试的核心价值到底是什么?
集合
Is it safe to open a mobile stock account? Is it reliable?
常用运算符与运算符优先级
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
线程池参数及合理设置
Add data to excel small and medium-sized cases through poi
[untitled]
MMO项目学习一:预热
众昂矿业:2022年全球萤石行业市场供给现状分析
Vagrant2.2.6 supports virtualbox6.1
XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
redis集群模拟消息队列
[OBS] qstring's UTF-8 Chinese conversion to blog printing UTF-8 char*
Reptile exercises (II)
Do you know several assertion methods commonly used by JMeter?
[C language] string function and Simulation Implementation strlen & strcpy & strcat & StrCmp