1、1输入 a,b 求 c = a + busing System;using System.Collections.Generic;using System.Text;namespace Proj2_1class Programstatic void Main(string args)int a, b, c;Console.Write(“a:“);a = int.Parse( Console.ReadLine();Console.Write(“b:“);b = int.Parse(Console.ReadLine();c = a + b;Console.WriteLine(“a+b=0“, c)
2、;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Proj2_2public partial class Form1 : Formpublic Form1()InitializeComponent();private void button1_Click(object sender, EventArgs e)2
3、int a, b, c;a = Convert.ToInt16(textBox1.Text);b = Convert.ToInt16(textBox2.Text);c = a + b;textBox3.Text = Convert.ToString(c); private void Form1_Load(object sender, EventArgs e)private void textBox2_TextChanged(object sender, EventArgs e)强制转换 P38using System;using System.Collections.Generic;using
4、 System.Text;namespace Proj3_1class Programstatic void Main(string args)int i=65,i1,i2;double d = 66.3456,d1,d2;char c = A,c1,c2;Console.WriteLine(“i=0:d5,d=1:f,c=2“, i, d, c);i1 = (int)d; /强制类型转换d1 = i; /隐式类型转换c1 = (char)i; /强制类型转换Console.WriteLine(“i1=0:d5,d1=1:f,c1=2“, i1, d1, c1);i2 = c; /隐式类型转换
5、d2 = (int)d; /强制类型转换c2 = (char)d; /强制类型转换Console.WriteLine(“i2=0:d5,d2=1:f,c2=2“, i2, d2, c2);3赋值两同学信息数据,并在图中输出结果 P44using System;namespace Proj3_2 class Program struct Student /类型声明应放在Main函数的外面 public int xh; /学号public string xm; /姓名public string xb; /性别public int nl; /年龄public string bh; /班号static
6、 void Main(string args) Student s1,s2; /定义两个结构类型变量s1.xh = 101;s1.xm = “李明“;s1.xb = “男“;s1.nl = 20;s1.bh = “07001“;Console.WriteLine(“学号:0,姓名:1,性别:2,年龄:3,班号:4“, s1.xh, s1.xm, s1.xb, s1.nl, s1.bh);s2 = s1; /将结构变量s1赋给s2s2.xh = 108;s2.xm = “王华“;Console.WriteLine(“学号:0,姓名:1,性别:2,年龄:3,班号:4“, s2.xh, s2.xm,
7、 s2.xb, s2.nl, s2.bh);声明枚举类型 color,给两成员赋值,定义三个变量,赋值运算输出相应值。P47using System;using System.Collections.Generic;using System.Text;namespace Proj3_3class Programenum Color Red=5, Green, Blue, White=1, Black /类型声明应放在Main函数的外面static void Main(string args)Color c1, c2,c3;Console.WriteLine(“Red=0,Green=1,Blu
8、e=2,White=3,Black=4“,Color.Red,Color.Green,Color.Blue,Color.White,Color.Black);Console.WriteLine(“Red=0,Green=1,Blue=2,White=3,Black=4“,(int)Color.Red,(int)Color.Gre4en,(int)Color.Blue,(int)Color.White,(int)Color.Black);c1 = Color.Red;c2 = c1 + 1;c3 = c2 + 1;Console.WriteLine(“c1=0,c2=1,c3=2“, c1, c
9、2,c3);Console.WriteLine(“c1=0,c2=1,c3=2“, (int)c1, (int)c2,(int)c3);位运算符运用 P50using System;using System.Collections.Generic;using System.Text;namespace Proj3_4class Programstatic void Main(string args)byte b1, b2, b3;b1 = 10;b2 =(byte) b1;Console.WriteLine(b2);b3 = (byte)(b1 13) Console.WriteLine(“输
10、入的数值太大!“);elsefor (i=0;i=n-1;i+)for (j=1;j15-i;j+)Console.Write(“ “); /每次循环显示2个空格c=1;Console.Write(“0 “,c);for (j=1;j=i;j+)c=c*(i-j+1)/j;if (c100) if (c10)Console.Write(“0 “,c); /显示3个空格elseConsole.Write(“0 “,c); /显示2个空格elseConsole.Write(“0 “,c); /显示1个空格Console.WriteLine();利用 /4 = 1-1/3+1/5-1/7+1/(4n
11、-3)-1/(4n-1) using System;using System.Collections.Generic;using System.Text;namespace Proj4_1610class Programstatic void Main(string args)double pi=0.0;int i;for (i=1;i=2000;i+)if (i%2=1)pi=pi+1.0/(2*i-1);elsepi=pi-1.0/(2*i-1);pi=4*pi;Console.WriteLine(“=0“, pi);输出三个数,其数值刚好等于其每个数字立方和(153=1+5+3)usin
12、g System;using System.Collections.Generic;using System.Text;namespace Proj4_17class Programstatic void Main(string args)int i, n, a, b, c;for (i = 100; i = 999; i+)n = i;c = n % 10; n = n / 10;b = n % 10; n = n / 10;a = n;if (a * a * a + b * b * b + c * c * c = i)Console.WriteLine(“0 1 2 = 3“, a, b, c,a*a*a+b*b*b+c*c*c);/Console.Write(“0 “, i);Console.WriteLine();
Copyright © 2018-2021 Wenke99.com All rights reserved
工信部备案号:浙ICP备20026746号-2
公安局备案号:浙公网安备33038302330469号
本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。