第2章节C语言程序设计入门g.ppt
文本预览下载声明
第 2 章 C语言程序设计入门
Evaluation only.
Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.
Copyright 2004-2011 Aspose Pty Ltd.
主要内容
输入输出语句
基本数据类型
算术运算符
关系运算符及逻辑运算符
简单的判断语句
Evaluation only.
Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.
Copyright 2004-2011 Aspose Pty Ltd.
本章重要概念
转义字符与转义序列
标识符的含义
破坏性读入和非破坏性读出
致命性错误与非致命性错误
Evaluation only.
Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.
Copyright 2004-2011 Aspose Pty Ltd.
2.2 简单C程序及其特点
例1:
void main()
{
printf(“Welcome to C!\n”);
}
每个C程序必须有一
个名为main()主函数
C程序用printf()函数
把信息输出到显示器上
例2:void main()
{
int a,b,c;
a=123;b=456;
c=a+b;
printf(“c=%d\n”,c);
}
使用的变量必须
定义后在引用
每个函数体必须用
一队{}括起来
每个语句以“;”结束。
函数体
Evaluation only.
Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.
Copyright 2004-2011 Aspose Pty Ltd.
例 转义字符举例
main()
{
printf(\101 \x42 C\n);
printf(\How are you?\\n);
printf(\\C Program\\\n);
printf(Turbo \C\);
}
运行结果:(屏幕显示)
A B C
”How are you?”
\C ProgramTurbo ‘C’
例 main()
{ printf(“Y\b=\n”);
}
运行结果:
屏幕显示:=
打印机输出:¥
Evaluation only.
Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.
Copyright 2004-2011 Aspose Pty Ltd.
格式:printf(“格式控制串”,输出表)
功能:按指定格式向显示器输出数据
返值:正常,返回输出字节数;出错,返回EOF(-1)
格式输出函数
输出表:要输出的数据(可以没有,多个时以“,”分隔)
格式控制串:包含两种信息
格式说明: [修饰符] ,用于指定输出格式
普通字符或转义序列:原样输出
格式字符
例 int a=3,b=4;
printf(“%d %d\n”,a,b);
printf(“a=%d , b=%d\n”,a,b);
输出结果: 3 4
a=3, b=4
Evaluation only.
Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0.
Copyright 2004-2011 Aspose Pty Ltd.
int a=567;printf ( “%d”,a);
int a=255;printf(“%x”,a);
int a=65;printf(“%o”,a);
int a=567;printf(“%u”,a);
char a=65;printf(“%c”,a);
printf(“%s”,“ABC”);
float a=567.789;printf(“%e”,a);
float a=567.789;printf(“%f”,a);
float a=567.789;printf(“%g”,a);
printf(“%%”);
567
ff
101
567
A
ABC
5.677890e+02
567.789000
567.789
%
Evaluation only.
Created with Aspose.Slides for .NET 3.5 Client Profile 5.2.0.0
显示全部