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

下载本文档

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

文档简介

.实验一 语言基础 一、实验目的 1. 熟悉Visual Stido.NET实验环境; 2. 掌握控制台程序的编写方法; 3. 掌握C#程序设计语言的语法基础; 4. 掌握控制语句和数组的使用。 二、实验要求 根据要求,编写C#程序,并将程序代码和运行结果写入实验报告。 三、实验内容 1. 编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text1 class Program static void Main(string args) System.Console.WriteLine(1.三y角?形?。 2.长方?形?。 请?选?择?相应|序号?:o); int i; i = int.Parse(Console.ReadLine(); if (i =1) double a, b, c, s,cir, area; System.Console.WriteLine(请?输?入?三y角?形?的?三y条?边?长:o); a = int.Parse(Console.ReadLine(); b = int.Parse(Console.ReadLine(); c = int.Parse(Console.ReadLine(); if (a + b c) & (a + c b) & (b + c a) cir = a + b + c; s = (a + b + c) / 2; area = Math.Sqrt(s * (s - a) * (s - b) * (s - c); System.Console.WriteLine(三y角?形?的?周长为a0, cir); System.Console.WriteLine(三y角?形?的?面?积y为a0, area); else System.Console.WriteLine(不?能构1成三y角?形?); if (i = 2) double a, b, cir, area; System.Console.WriteLine(请?输?入?长方?形?的?边?长:o); a = int.Parse(Console.ReadLine(); b = int.Parse(Console.ReadLine(); cir = 2 * a +2 * b ; area = a * b; System.Console.WriteLine(长方?形?的?周长为a0, cir); System.Console.WriteLine(长方?形?的?面?积y为a0, area); 2. 编写一个控制台应用程序,可根据输入的月份判断所在季节。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text2 class Program static void Main(string args) int i; System.Console.WriteLine(请?输?入?月?份Y:o); i = int.Parse(Console.ReadLine(); if (i = 1) | (i = 2) | (i = 3) System.Console.WriteLine(此?月?份Y在春o季?); else if (i = 4) | (i = 5) | (i = 6) System.Console.WriteLine(此?月?份Y在夏?季?); else if (i = 7) | (i = 8) | (i = 9) System.Console.WriteLine(此?月?份Y在秋?季?); else if (i = 10) | (i = 11) | (i = 12) System.Console.WriteLine(此?月?份Y在冬?季?); else System.Console.WriteLine(输?入?不?合?理月?份Y,?无T法判D断?); 3. 编写程序,用 while 循环语句实现下列功能:有一篮鸡蛋,不止一个,有人两个两个数,多余一个,三个三个数,多余一个,再四个四个地数,也多余一个,请问这篮鸡蛋至少有多少个。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text3 class Program static void Main(string args) int x, sum = 2; while (sum 100000) x = sum; if (x % 2 = 1 & x % 3 = 1 & x % 4 = 1) System.Console.WriteLine(最?小?鸡|蛋数y为a0, sum); return; sum+; 4. 编写程序,计算数组中奇数之和和偶数之和。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text4 class Program static void Main(string args) int arr = new int5; int sum1 = 0, sum2 = 0; System.Console.WriteLine(请?输?入?数簓组哩?中D的?数簓:阰); for (int i = 0; i 5; i+) arri = int.Parse(Console.ReadLine(); for (int i = 0; i 5; i+) if (arri % 2 = 0) sum1 = sum1 + arri; if (arri % 2 != 0) sum2 = sum2 + arri; System.Console.WriteLine(数簓组哩?中D所有瓺偶?数簓之?和为a0, sum1); System.Console.WriteLine(数簓组哩?中D所有瓺偶?数簓之?和为a0, sum2); 4.5. 编写程序,找一找一个二维数组中的鞍点(即该位置上的元素值在行中最大,在该列上最小。有可能数组没有鞍点)。要求: 1. 二维数组的大小、数组元素的值在运行时输入; 2. 程序有友好的提示信息。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace text4._1 class Program static void Main(string args) int, a = new int3, 4; int i, j, max, p, k; bool flag = true, NoExistNaddle = false; for (i = 0; i = 2; i+) for (j = 0; j = 3; j+) Console.Write(请?输?入?二t维?数簓组哩0,1=, i, j); ai, j = int.Parse(Console.ReadLine(); for (i = 0; i = 2; i+) max = ai, 0; p = 0; for (j = 1; j = 3; j+) if (max ai, j) max = ai, j; p = j; else p = 0; for (k = 0; k ak, p) flag = false; break; if (flag = true) Console.WriteLine( a0,1=2, i, p

温馨提示

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

评论

0/150

提交评论