c#-实验一.doc_第1页
c#-实验一.doc_第2页
c#-实验一.doc_第3页
c#-实验一.doc_第4页
c#-实验一.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验一 语言基础 一、 实验目的 1. 熟悉 Visual Stido.NET 实验环境; 2. 掌握控制台程序的编写方法; 3. 掌握 C#程序设计语言的语法基础; 4. 掌握控制语句和数组的使用。 二、 实验要求 根据要求,编写 C#程序,并将程序代码和运行结果写入实验报告。 三、 实验内容 1. 编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出。 实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace sy1_1 class Program static void Main(string args) int n=1; while (n != 0) Console.WriteLine(请选择你输入的图形:1.三角形;2.长方形;0.退出); n = int.Parse(Console.ReadLine(); if (n = 1) Console.WriteLine(请输入三角形的三条边(每行输入一个数值):); float a = float.Parse(Console.ReadLine(); float b = float.Parse(Console.ReadLine(); float c = float.Parse(Console.ReadLine(); double l = a + b + c; double p = l / 2; double s = Math.Sqrt(p * (p - a) * (p - b) * (p - c); Console.WriteLine(三角形周长为:0, l); Console.WriteLine(三角形的面积为:0, s); if(n=2) Console.WriteLine(请输入长方形的长和宽(每行输入一个数值):); float a = float.Parse(Console.ReadLine(); float b = float.Parse(Console.ReadLine(); double l = (a + b) * 2; double s = a * b; Console.WriteLine(长方形的周长为:0, l); Console.WriteLine(三角形的面积为:0, s); 实验截图: 2. 编写一个控制台应用程序,可根据输入的月份判断所在季节。实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace sy1_2 class Program static void Main(string args) int a = 0; Console.WriteLine(请输入你要判断的月份,或按 0 退出:); a = int.Parse(Console.ReadLine(); while (a != 0) if (a 12 | a = 0) Console.WriteLine(输入的月份不对); else if (a = 3) Console.WriteLine(你输入的是春季:); else if (a = 6) Console.WriteLine(你输入的是夏季:); else if (a = 9) Console.WriteLine(你输入的是秋季:); else if (a =1) if (n % 2 = 0 & n % 3 = 0 & n % 4 = 0) break; n+; Console.WriteLine(这筐鸡蛋至少有0个,n+1); 实验截图:4. 编写程序,计算数组中奇数之和和偶数之和。 实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace sy1_4 class Program static void Main(string args) Console.WriteLine(请输入数组中的数值,以空格分开,或输入 # 退出程序); string str = Console.ReadLine(); while (str .ToCharArray().First()!= #) string sarr = str.Split( ); float a = new floatsarr.Length; float q = 0, p = 0; for (int i = 0; i sarr.Length; i+) ai = float.Parse(sarri); if (ai % 2 = 0) q = q + ai; else p = p + ai; Console.WriteLine(奇数之和为:0, p); Console.WriteLine(偶数之和为:0, q); Console.WriteLine(请输入数组中的数值,以空格分开,或输入 # 退出程序); str = Console.ReadLine(); 实验截图:5. 编写程序,找一找一个二维数组中的鞍点(即该位置上的元素值在行中最大,在该列上最小。有可能数组没有鞍点)。要求: 1)二维数组的大小、数组元素的值在运行时输入; 2)程序有友好的提示信息。 实验代码:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace sy1_5 class Program static void Main(string args) Console.WriteLine(请选择:1.输入矩阵,0.退出); int flag = int.Parse(Console.ReadLine(); while (flag = 1) Console.WriteLine(请输入二维矩阵的行数和列数,用空格分开); string str = Console.ReadLine(); string strr = str.Split( ); int row = int.Parse(strr0); int column = int.Parse(strr1); float, a = new floatrow, column; Console.WriteLine(请输入二维矩阵元素:); for (int i = 0; i row; i+) string s = Console.ReadLine(); string ss = s.Split( ); if (ss.Length != column) Console.WriteLine(输入列数不对:); break; for (int j = 0; j column; j+) ai, j = float.Parse(ssj); int c = 0; for (int i = 0; i row; i+) int maxj = 0; for (int j = 0; j ai, maxj) maxj = j; int minx = 0; for (int j = 0; j row; j+) if (aj, maxj aminx, maxj) minx = j; if (ai, maxj = aminx, maxj) Console.Write(马鞍点0,1:2+n,minx,maxj,aminx,maxj

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论