C#程序设计实验报告实验指导书-邵佳楠(2)

2020-04-14 16:49

金陵科技学院实验报告

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


C#程序设计实验报告实验指导书-邵佳楠(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:浅谈社会主义核心价值观

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: