c程序设计教程李春葆课后编程题答案
输入a,b求c = a + b
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj2_1
{
class Program
{
static 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);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Proj2_2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
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)
{
}
}
}
强制转换P38
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj3_1
{
class Program
{
static 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; //隐式类型转换
d2 = (int)d; //强制类型转换
c2 = (char)d; //强制类型转换
Console.WriteLine("i2={0:d5},d2={1:f},c2={2}", i2, d2, c2);
}
}
}
赋值两同学信息数据,并在图中输出结果P44
using System;
namespace Proj3_2
{cl