当前位置:首页 > C#程序设计实验报告实验指导书-邵佳楠
金陵科技学院实验报告
2、编写一个Windows窗体应用程序,输入自己的班级、学号、姓名并显示。 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 WindowsFormsApplication2 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
MessageBox .Show (\班级:\姓名:\+\学号:\
} } }
3
金陵科技学院实验报告
3、编写一个程序,用来判断输入的是大写字母,小写字母,数字还是其他的字符(if)。 using System;
using System.Collections.Generic; using System.Linq; using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Console.WriteLine(\请输入一个字符:\
char c = Convert.ToChar(Console.ReadLine()); if (c >= 'a' && c <= 'z')
Console.WriteLine(\该字母是小写字母\ else if (c >= 'A' && c <= 'Z')
Console.WriteLine(\该字母是大写字母\ else if (char.IsDigit(c))
Console.WriteLine(\该字母是数字\ else
Console.WriteLine(\其它字符\ Console.ReadLine(); } } }
4
金陵科技学院实验报告
4、编写一个程序,实现简单的加、减、乘、除的运算(switch)。 using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication3 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
int num1 = int.Parse(txtnum1.Text); int num2 = int.Parse(txtnum2.Text); switch (txtop.Text) {
case \
txtresult.Text = (num1 + num2) + \ case \
txtresult.Text = (num1 - num2) + \ case \
txtresult.Text = (num1 * num2) + \ case \
txtresult.Text = (num1 / num2) + \ default:
txtresult.Text = \ }
5
金陵科技学院实验报告
} } }
5、定义一个一维数组,通过键盘输入10个两位整数,用foreach循环输出其中的内容。 并求出其中的最大值和平均值,把结果显示出来。 using System;
using System.Collections.Generic; using System.Linq; using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication2 {
class Program {
static void Main(string[] args) {
int[] a = new int[10]; int i = 0;
while (i < a.Length) {
Console.Write(\请输入第{0}个数据:\ a[i] = Convert.ToInt32(Console.ReadLine()); if (a[i] >= 10 && a[i] <= 99) i++; }
Console.Write(\数组内容为:\ foreach (int j in a) {
Console.Write(\ }
Console.WriteLine();
Console.WriteLine(\最大值: \ Console.WriteLine(\平均值: \ Console.ReadLine(); } } }
6
共分享92篇相关文档