当前位置:网站首页>C - sequential structure
C - sequential structure
2022-07-05 19:49:00 【Can't learn java】
Sequential structure
1、 Assignment statement
- Add
A semicolonThis 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.35670The number of output items is greater than the number of output formats ,
Redundant items are not outputThe 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 fetchOperator
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,3example 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,6789example 3: Real data input , When inputting real data ,
Cannot specify decimaldigitfloat f; scanf("%7.2f",&f); // Error can only specify width , You cannot specify the number of decimal placesexample 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,BCharacter 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);
边栏推荐
- 强化学习-学习笔记4 | Actor-Critic
- Which securities company is better and which platform is safer for mobile account opening
- How to realize the Online timer and offline timer in the game
- C#应用程序界面开发基础——窗体控制(6)——菜单栏、工具栏和状态栏控件
- [AI framework basic technology] automatic derivation mechanism (autograd)
- [Collection - industry solutions] how to build a high-performance data acceleration and data editing platform
- Common - Hero Minesweeper
- [FAQ] summary of common causes and solutions of Huawei account service error 907135701
- 城链科技数字化创新战略峰会圆满召开
- 国海证券在网上开户安全吗?
猜你喜欢

Necessary skills for interview in large factories, 2022android will not die, I will not fall

Using repositoryprovider to simplify the value passing of parent-child components

Force buckle 729 My schedule I

城链科技数字化创新战略峰会圆满召开

司空见惯 - 英雄扫雷鼠

Inventory of the most complete low code / no code platforms in the whole network: Jiandao cloud, partner cloud, Mingdao cloud, Qingliu, xurong cloud, Jijian cloud, treelab, nailing · Yida, Tencent clo

Summer Challenge database Xueba notes, quick review of exams / interviews~

IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍

C application interface development foundation - form control (5) - grouping control

C#应用程序界面开发基础——窗体控制(5)——分组类控件
随机推荐
什么是面上项目
Xaas trap: all things serve (possible) is not what it really needs
webuploader文件上传 拖拽上传 进度监听 类型控制 上传结果监听控件
[hard core dry goods] which company is better in data analysis? Choose pandas or SQL
打新债在哪里操作开户是更安全可靠的呢
Reflection and imagination on the notation like tool
Android面试,android音视频开发
通配符选择器
Information / data
Microwave radar induction module technology, real-time intelligent detection of human existence, static micro motion and static perception
四万字长文说operator new & operator delete
测试的核心价值到底是什么?
函数的概念及语法
[FAQ] summary of common causes and solutions of Huawei account service error 907135701
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
建议收藏,我的腾讯Android面试经历分享
Hiengine: comparable to the local cloud native memory database engine
Bitcoinwin (BCW)受邀参加Hanoi Traders Fair 2022
[untitled]
Wildcard selector