《C#应用程序设计教程习题答案.docx》由会员分享,可在线阅读,更多相关《C#应用程序设计教程习题答案.docx(61页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、C#应用程序设计教程习题答案章后习题答案第1章 C#开发环境一、单选题1. B 2. D 3. A 4. B 5. A二、填空题1. Main 2. /三、综合题1、using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp1 class Program static void Main(string args) Console.WriteLine(我要学好C#语言); 2、四、上机编程1、u
2、sing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp3 class Program static void Main(string args) int i,j; for(i=0; i0;j-) Console.Write(*); Console.WriteLine(); 2、using System;using System.Collections.Generic;using System
3、.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApp1 public partial class Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e)
4、 String a = this.textBox1.Text; String b = this.textBox2.Text; double c = double.Parse(a) - double.Parse(b); this.textBox3.Text = c.ToString(); 第2章 C#语法基础一、单选题1. B 2. A 3. A 4. D 5. C 6. B 7. D 8. B 9. D二、填空题1. -2 -4 -6 2. 27三、综合题1、using System;using System.Collections.Generic;using System.Linq;usin
5、g System.Text;using System.Threading.Tasks;namespace ConsoleApp4 class Program static void Main(string args) Console.Write(输入一个时间:); int i =int.Parse(Console.ReadLine(); if(i24) Console.WriteLine(输入时间格式错误); else if(i 999 | i 100) Console.WriteLine(输入数字不符合要求!); else a = i % 10; b = i / 10 % 10; c = i
6、 / 100; Console.WriteLine(该数字的逆序数是012:, a, b, c); 3、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace WindowsFormsApp2 public partial c
7、lass Form1 : Form public Form1() InitializeComponent(); private void button1_Click(object sender, EventArgs e) string a = this.textBox1.Text; double b = Math.Sqrt(double.Parse(a); this.textBox2.Text = b.ToString(); 第3章 程序控制结构一、单选题1. C 2. D 3. C 4. A二、填空题1. 912152. 死循环 三、综合题1、using System;using Syste
8、m.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _3._1 class Program static void Main(string args) int temp; int number = new int4; Console.WriteLine(请输入四个数:); for (int i = 0; i 4; i+) numberi = Convert.ToInt32(Console.ReadLine(); for (int i = 0; i 3;
9、i+) for (int j = i+1; j 4; j+) if (numberi numberj) temp = numberi; numberi = numberj; numberj = temp; Console.WriteLine(四个数中最大值为:0,最小值为:1,number0,number3); 2、For循环:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _3._2 class Pr
10、ogram static void Main(string args) int number = 1; Console.WriteLine(下列数字为用for循环表示:); for (int i = 1; i 21; i+) Console.Write(0 ,i); if (number % 5 = 0) Console.WriteLine(); number+; while循环:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tas
11、ks;namespace _3._2_2 class Program static void Main(string args) int i= 1; Console.WriteLine(下列数字为用while循环表示:); while (i 21) Console.Write(0 ,i); if (i % 5 = 0) Console.WriteLine(); i+; 3、using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;n
12、amespace _3._3 class Program static void Main(string args) int sum, temp; for (int i = 1000; i 0) sum += (temp % 10) * (temp % 10) * (temp % 10) * (temp % 10); temp /= 10; if (sum = i) Console.WriteLine(0, i); 4、using System;using System.Collections.Generic;using System.Linq;using System.Text;using
13、System.Threading.Tasks;/*编写一个字符串,用foreach循环,统计并输出大小写字母*/namespace _3._4 class Program static void Main(string args) string str = Console.ReadLine(); int num = 0, da = 0, xiao = 0; foreach (char temp in str) if (char.IsNumber(temp) num+; if (char.IsLower(temp) xiao+; if (char.IsUpper(temp) da+; ; Con
14、sole.WriteLine(数字有0个,小写字母有1个,大写字母有2个, num, xiao, da); 5、using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _3._5 class Program static void Main(string args) double price,number; Console.WriteLine(请输入购买金额:); price = double.Parse(Co
15、nsole.ReadLine(); Console.WriteLine(请输入是否有金卡和银行卡(金卡输入:g,银行卡输入:b,无卡请输入:0); String card = Console.ReadLine(); number = price; if (price 10000) price = price - 800; else if (price 8000) price = price - 600; else if (price 5000) price = price - 300; if (card.Equals(g) price = price * 0.99; else if(card.
16、Equals(b) price = price * 0.995; Console.WriteLine(实际优惠金额为:0,number-price); Console.WriteLine(实际支付金额为:0,price); 6、using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace _3._6 class Program static void Main(string args) double a, b, su
17、m; int s, i; double w = 0; string z = ; a = 0; b = 0; sum = 0; s = 0; Console.Write(要实现加、减、乘、除请输入1;要实现阶乘请输入2: ); w = Convert.ToDouble(Console.ReadLine(); if (w = 1) Console.Write(请输入数值A: ); a = Convert.ToDouble(Console.ReadLine(); Console.Write(请选择运算符号(+,-,*,/): ); z = Console.ReadLine(); Console.Wr
18、ite(请输入数值B: ); b = Convert.ToDouble(Console.ReadLine(); switch (z) case +: sum = a + b; break; case -: sum = a - b; break; case *: sum = a * b; break; case /: if (s != 0) sum = a / b; else Console.Write(除数不能为0!n); break; Console.Write(结果为:,sum); Console.ReadLine(); else if (w = 2) sum = 1; Console.W
19、rite(请输入要求阶乖数: ); s = Convert.ToInt32(Console.ReadLine(); if (s != 0) for (i = 1; i c) & (a + c b) & (b + c a) if (a = b) & (b = c) Console.WriteLine(等边三角形); else if (a != b) & (a != c) & (b != c) Console.WriteLine(一般三角形); else Console.WriteLine(等腰三角形); else Console.WriteLine(不能构成三角形); 3、class Program static void Main(string args) int c = new int10; int i = 0; Console.WriteLine(请输入十进制数字:); int a = int.Parse(Console.ReadLine(); while (a 0) ci = a % 2; a = a / 2; i+; Console.WriteLine(改数的二进制数为:); for (; i=0; i-) Console.Write(0, ci); 4、class Program static void Ma