C#程序设计案例教程 作者 王明福 源代码习题答案 第3章.pptVIP

  • 38
  • 0
  • 约8.22千字
  • 约 43页
  • 2015-12-09 发布于未知
  • 举报

C#程序设计案例教程 作者 王明福 源代码习题答案 第3章.ppt

2. if-else语句 语法形式: 3. 嵌套的if语句 语法形式: if ( 条件1 ) 语句1 else if ( 条件2 ) 语句2 else if ( 条件3 ) 语句3 ┇ else 语句n 【例3-3】已知符号函数: -1 (x0) y= 0 (x=0) 1 (x0) 要求编一程序,输入一个x值,输出y 值。 方法 1: 嵌套在else子句中 static void Main(string[] args) { int x, y; Console.WriteLine(“please input x:”); string s = Console.ReadLine(); x = int.Parse(s); if(x0) y= -1; else if(x= =0) y=0; else y=1; Console.WriteLine(“x={0}, y={1}”,x,y); } 方法 2: 嵌套在if子句中。 static void Main(string[] args) { int x, y; Console.W

文档评论(0)

1亿VIP精品文档

相关文档