已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter TInpu and OutputContents1Data output2Data input3Examples4Control flow-sequenceControl flow-sequenceABNotes in sequence structure Declaration statements first ,then execution statements; Execution statements review: Assignment statement Compond statement expression statementInput /output function call statementInitialization : assign value while declaration;main( ) int a;a=5;main( ) int a=5;Data outputv Character input and outputv Formatted input and outputYour programs will need to include the standard I/O header file so do: #include Input and output are not part of the C There are a set of functions that provide input and output in standard library.NoteCharacter outputputchar(char variable)Formatoutputs a single character to screen.Role Only single characterResult #includeData output#includemain( ) char c=a;putchar( c);Examplemain( ) char c1, c2,c3;c1=a;c2=b;c3=c;putchar(c1);putchar(c2);putchar(c3); How many characters will be displayed ?How about their arrangement? Data outputData outputResultFormatRole NoteFormatted outputprintf ( control string, argument list )Output the variables value in the given format on screenNo argument, only print out control string.printf(“Hello!”);Arguments including constants, variables, mathematical expressionsData outputtype conversion specifier. Control string:Format Output% d output int value in decimal form % o output int value in octal form % x output int value in hexadecimal form% ld: output long int value in decimal form% u output unsign int value in decimal form% f output float value in decimal form% e output float value in exponent formData outputFormat Output% c Output one character% s Output a string% g Output the shorter one between %e and %f% md the output width is m , flush right% -md the output width is m , flush left% m.nf the output width is m , decimal part is n , flush right% -m.nf the output width is m , decimal part is n , flush lefttype conversion specifier printf uses its first argument to decide how many arguments follow and what their type is . It will get confused ,and you will get wrong answers, if there are not enough arguments of if they are the wrong type. Data outputprintf(“%d,%d n”,a,b); if: a=5,b=8a=5,b= 8 printf(“a=%d,b=%dn”,a,b); 5, 8 printf(“%5d%5dn”,a,b); 5 8printf(“Turbo C”); Turbo Cprintf(“%s ”, “Turbo C”); Turbo Cmain() int a=16; char e =A; unsigned b; long c; float d;b=65535; c=123456; d=123.45;printf(“a=%d,%4d,%- 6d,c=%dn”,a,a,a,c);printf(“%o,%x,%u,%dn”,b,b,b,b );printf(“%f,%e,%13.3e,%gn”,d,d,d,d);printf(“%c,%s,%7.3sn”,e,” China”,”Beijing”);a=16, 16,16 , c= - 7616177777, ffff ,65535 , -1123.450000,1.234500e+002, 1.235e+002,123.45A, China, BeiData outputData outputFormat 2 Format 3Format 1 Character input functions and formatted input function1、 character input Inputs a single character from keyboard.Input ,no display ,no Entergetch( )Input and display ,no Entergetche( )After inputing ,one should press Enter keygetchar( )main() int a=3,b=5;printf(“%d,%d,%dn”,a,b, a+b);getch();Data input main( ) char c;c=getchar( );putchar(c); Output the character what you input 2 formatted inputscanf(control string, arguments list)Format:scanf reads characters from the standard input, interprets them according to the specification in format and stores the results through the remaining arguments.Result: the arguments list must be address , indicate where the corresponding converted input should be stored.Note:int a,b;scanf(“%d,%d”, Data input Discussion Format control string similar to printf The arguments are ADDRESS of variables If the inputs dont match, the type conversion specifier, the scanf will stop reading the inputs,return an errorscanf will terminate entry of string when it reads the first space or new line.If the input string length is larger than 3,The first 3 chars are assigned to address others are K;scanf(“%3d”,input: 123456789 K is 123main() int a; float b,c;scanf(“%2d%3f%4f”,printf(“a=%d,b=%f,c=%fn”,a,b,c);input: 12345678987654321output?a=12,b=345.000000,c=6789.00000012 345 6789Data input If additional chars are inserted in control string, they must appear in the input a,b;scanf(“%d%d”, scanf(“%d ,%d”, 3 , 5 scanf(“a =%d,b=%d”, Input: a=3,b=5 char c1,c2,c3; scanf(“%c%c%c ”, A B
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 跨境数字碳中和数据中心中跨国AI模型训练碳排放核算-基于国际绿色数据中心联盟AI模型训练碳足迹核算指南及各国AI训练能耗差异规范分析
- 2026年音乐节跨界联名营销效果评估报告
- 建设单位与监理方管理费协议书
- 2026合作项目终止清算协议范本三篇
- 安全网格化管理台账规范
- 2026年湖北黄冈市浠水县实验初级中学等校春季七年级期中综合素质监测地理试卷
- 2026年江西赣州市中考一模地理试卷
- 2026年山东青岛市李沧区中考二模地理试卷
- 倡导环保节能的无纸化假期申请
- 2026年环境保护与可持续发展战略治理试卷
- 2025年兴业银行招聘考试(数据类)历年参考题库含答案详解(5套)
- 兰州理工大学数学试卷
- 科技创新型企业股权激励对财务绩效影响分析-以京东方为例
- 近三年安全生产业绩证明
- 成本实操-席梦斯床垫成本计算实例
- T/CSMT-DZ 005-2023显示用量子点材料性能测试方法
- T/CIE 186-2023业务研发安全运营一体化能力成熟度模型
- 广东省深圳市二模2025届高三数学试卷及答案
- 2025年热烈庆祝建党104周年党史知识竞赛题库及答案(共300题)
- 进驻学校保安服务方案
- 《工程勘察设计收费标准》(2002年修订本)
评论
0/150
提交评论