已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年生物质锅炉供热行业分析报告及未来发展趋势报告
- 2026年哈尔滨市广播电视台(融媒体中心)人员招聘考试备考试题及答案详解
- 2026年襄樊市森林保护站事业单位人员招聘考试备考试题及答案详解
- 2026年晋城市财政系统事业单位人员招聘考试备考试题及答案详解
- 2026年RSU行业分析报告及未来发展趋势报告
- 记账付款协议书
- 2026重庆建峰浩康化工有限公司招聘1人考试备考题库及答案解析
- 证件借用协议书
- 诉讼时效协议书
- 诚信考试协议书
- 【可见光室内定位系统的设计与实现(论文)8000字】
- 人教版五年级数学下册测试题(全套)-五年下册人教数学测试题
- 网络传播概论(第5版)课件 第3、4章 网络传播形式的流变、网络传播的多重策略
- T-CPA 006-2024 造纸用湿强剂 聚酰胺环氧氯丙烷PAE
- JBT 5300-2024 工业用阀门材料 选用指南(正式版)
- 广东省普通高中学生档案
- 《跨境电商支付与结算》-教案
- 哈萨克斯坦劳动法中文版
- 道德经原文及注释
- 第十一章-玛莎·E·罗杰斯的整体人科学模式
- 四年级下册数学-猜数游戏北师大版课件
评论
0/150
提交评论