当前位置:网站首页>c——顺序结构
c——顺序结构
2022-07-05 19:40:00 【Java学不会】
1、赋值语句
- 在赋值表达式的后面加上
分号
就构成了赋值语句。
2、数据的输出
字符原样输出
指定宽度输出:如果长度不够向左边补空格
%m.nf: m—代表数据总长,n代表小数位数,n代表小数位数
- 实际长度>n(四舍五入)
- 实际长度<n(右边补零)
int a=234; printf("a=%4d\n",a); printf("a=%2d\n",a); 输出结果: 234 234 float f=24.3567; printf("f=%7.2f\n",f); printf("f=%10.5f\n",f); 输出结果: 24.36 24.35670
输出项个数大于输出格式个数,
多余的项不输出
整型数据范围的最大值+1得范围的最小 值,范围的最小值-1得范围最大值
3、数据的输入
&取地址
运算符
间隔符的数量没有限制
,并且可以混用
整型数据输入如果没有其它符分隔,用空格或回车分隔输入项必须是变量的地址
例1:
int a,b,c; scanf("%d%d%d",&a,&b,&c); printf("%d,%d,%d\n",a,b,c); 现要给a赋值1,b赋值2,c赋值3,则 输入写法:1 2 3 输出结果:1,2,3
例2:指定输入数据的宽度
int a,b,c; scanf("%2d%3d%4d",&a,&b,&c); printf("%d,%d,%d\n",a,b,c); 从键盘输入:1234567890 输出结果:12,345,6789
例3:实型数据输入,实型数据输入时,
不能指定小数
位数float f; scanf("%7.2f",&f); //错误只能指定宽度,不能指定小数位数
例4:字符的输入与输出,char类型只接受一个字符,%c前一定不能有空格
char c1,c2; scanf("%c%c",&c1,&c2) printf("%c,%c\n",c1,c2); 现给c1赋值字符A,c2赋值字符B 输入:AB 输出:A,B
字符的输入函数:
getchar()
字符的输出函数:
putchar(ch)
4、复合语句与空语句
4.1、复合语句
形式:{ }
{ a=2;b=3;c=a+b;}
4.2、空语句
- 形式:
;
5、程序实例
输入两个整数a和b,将其值交换后输出
例1:
int a,b,t; scanf("%d%d",&a,&b); t=a; a=b; b=t; printf("%d,%d\n",a,b);
例2:
int a,b; scanf("%d%d",&a,&b); a=a+b; b=a-b; a=a-b; printf("%d,%d\n",a,b);
边栏推荐
- Reptile exercises (II)
- Information / data
- Using repositoryprovider to simplify the value passing of parent-child components
- XaaS 陷阱:万物皆服务(可能)并不是IT真正需要的东西
- 四万字长文说operator new & operator delete
- 【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
- C application interface development foundation - form control (6) - menu bar, toolbar and status bar controls
- How to apply smart contracts more wisely in 2022?
- Oracle故障处理:Ora-10873:file * needs to be either taken out of backup or media recovered
- okcc呼叫中心有什么作用
猜你喜欢
Fuzor 2020 software installation package download and installation tutorial
word如何转换成pdf?word转pdf简单的方法分享!
How MySQL queries and modifies JSON data
IBM大面积辞退40岁+的员工,掌握这十个搜索技巧让你的工作效率至上提高十倍
Fuzor 2020软件安装包下载及安装教程
MMO項目學習一:預熱
Android面试,android音视频开发
Password reset of MariaDB root user and ordinary user
如何实现游戏中的在线计时器和离线计时器
四万字长文说operator new & operator delete
随机推荐
手机开户选择哪家券商公司比较好哪家平台更安全
Webuploader file upload drag upload progress monitoring type control upload result monitoring control
How MySQL queries and modifies JSON data
third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctl
PG基础篇--逻辑结构管理(用户及权限管理)
Worthy of being a boss, byte Daniel spent eight months on another masterpiece
Relationship between floating elements and parent and brother boxes
Shell编程基础(第8篇:分支语句-case in)
HiEngine:可媲美本地的云原生内存数据库引擎
Is it safe to open a mobile stock account? Is it reliable?
Two pits exported using easyexcel template (map empty data columns are disordered and nested objects are not supported)
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
The relationship between temperature measurement and imaging accuracy of ifd-x micro infrared imager (module)
软件测试工程师是做什么的?待遇前景怎么样?
Fuzor 2020 software installation package download and installation tutorial
深度学习 卷积神经网络(CNN)基础
Hiengine: comparable to the local cloud native memory database engine
常用运算符与运算符优先级
Password reset of MariaDB root user and ordinary user
Hiengine: comparable to the local cloud native memory database engine