- 1
- 0
- 约1.67千字
- 约 58页
- 2016-07-26 发布于湖北
- 举报
第4章 控制结构;程序的基本控制结构;表达式语句;函数调用语句;空语句;复合语句 ;【例4_1】 计算圆的周长和面积。
#include iostream.h
#include math.h
#define PI 3.14
int main()
{double radius, area; //说明语句
radius = 3.0 ;
{
double perimeter; //说明语句
perimeter = PI * 2 * radius;
cout The perimeter is : “
perimeter \n ;
} //复合语句
area = PI * pow(radius,2);
cout The area of the circle is : “
area \n ;
return 0;
};if 语句 ;if-else 语句(1) ;if-else 语句示例:
if (grade = 60)
cout Passed !\n;
else
cout Failed !\n;
(错:elsecout Failed !\n;)
;if-else 语句(2) ;;if-else 语句(3) ;;switch 语句一般形式
switch (条件表达式 )
{case 常量表达式1
原创力文档

文档评论(0)