金陵科技学院实验报告
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
金陵科技学院实验报告
6、定义一个5行5列二维数组,用随机数给二维数组赋值,按照5行5列的格式显示 出二维数组的内容,把最大值显示出来。 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[5, 5]; int max;
Random rnd = new Random();
Console.WriteLine(\二维数组的内容为:\ for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
a[i, j] = rnd.Next(10, 99); Console.Write(\ }
Console.WriteLine(); }
7
金陵科技学院实验报告
max = a[0, 0];
for (int i = 0; i < 5; i++) for (int j = 0; j < 5; j++) if (a[i, j] > max) max = a[i, j];
Console.WriteLine(\最大值:\ Console.ReadLine(); } } }
8