c#实训基础题部分._第1页
c#实训基础题部分._第2页
c#实训基础题部分._第3页
c#实训基础题部分._第4页
c#实训基础题部分._第5页
已阅读5页,还剩62页未读 继续免费阅读

付费下载

下载本文档

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

文档简介

1、使用控制台方式实现如下应用程序:基础题部分:1写一个程序,完成以下功能:从键盘上输入5个整数,求出最大最小值。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplicationlclass Programstatic void Main( string args)Console .Write( please enter 5 figure: );double a = new double 5;for ( int i = 0; i 5; i+)a

2、i =int .Parse( Console .ReadLine();double min = a0;double max = a0;for ( int j=O;j 4;j+)if (max aj + 1)max = aj+1;Console .WriteLine( max = +max);for ( int p = 0;p ap + 1)min = ap+1;Console .WriteLine( min = +min);2、写一个程序,打印出九九乘法表。using System;using System.Collections.Generic;using System.Linq;using

3、 System.Text;namespace ConsoleApplication1class Programstaticvoid Main( string args)for(int i = 1; i 10; i+)for ( int j = 1;ji+1;j+)Console .Write( +i + X + j += + (i * j);Console .WriteLine();3、分别使用for循环和while循环设计一个程序,计算从 1加到100的和。For循环:using System;using System.Collections.Generic;using System.Lin

4、q;using System.Text;namespace ConsoleApplication1class Programint sum = 0;static void Main( string args)for ( int i = 1; i = 100; i+)sum = sum + i;Console .WriteLine( sum = + sum);While循环:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1

5、class Programstatic void Main( string int sum = 0;int i = 1;while (i = 100)args)sum i+;=sum + i;Console .WriteLine(sum = + sum);4、利用数学类提供的平方根方法计算并输出1.0, 2.0, 3.0,,10.0的平方根。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1class Programdoub

6、le x = 0.0;for ( double i = 1.0; i = 10.0; i=i+1)x =Math.Sqrt(i);Console .WriteLine(i +A2= + x);5、 随机数方法产生5个110 (包括1和10)之间的整数。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1class Programstatic void Main( string args)for ( int i = 0; i 5

7、; i+)Randomran = new Randon(i);int Randomkey = ran.Next(1, 10);Console .WriteLine(Randomkey);6、 编程实现:随机产生120之间的整数,总共生成 1000次,统计其中生成的整数0, 1,2, 3,20的个数分别是多少,并输出统计结果(每5个数一行)。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1class Programstati

8、c void Main( string args)int A;A =new int 21;for ( int i = 0; i 1000; i+)Randomran = new Random);int Randomkey = ran.Next(0, 20);int x = Randomkey;Ax+;for ( int j = 0; j 20; j+)Console .Write(Aj+);if (j + 1) % 5 = 0)Console .WriteLine();7、统计字符串“ a12bcd?A*B34 ”中分别有多少个数字和字母。using System;using System.C

9、ollections.Generic;using System.Linq;using System.Text;namespace ConsoleApplicationlclass Programstatic void Main( string args)int num = 0;int alpha = 0;String s =a12bcd?A*B34;for ( int i = 0; i s.Length; i+)String ch = s.Substring(i, 1);if ( charsNumber(ch,0)num+;charsLower(ch,0)else if ( charsUppe

10、r(ch,O) |alpha+;Console .WriteLine( num = +num+ ,alpha = +alpha);&编写程序,要求用户输入月份号码,然后显示该月的英文名称。例如,如果用户输入2,程序应显示February。要求月的英文名称存于数组中。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1class Programstatic void Main( string args)string month

11、= new string12;/ month =(January,February,March,April,May,June,July,August,September,October,No vember,December);Console .Write(请输入您要的月数:”);string a = Convert .ToString( Console .ReadLine();switch (a)case 1Console .WriteLine( January); break;case 2:Console .WriteLine( February); break;case 3:Console

12、 .WriteLine( March); break;case 4:Console .WriteLine( April);break;case 5:Console .WriteLine( May); break;case 6:Console .WriteLine( June); break;case 7:Console .WriteLine( July); break;case 8:Console .WriteLine( August); break;case 9:Console .WriteLine( September);break;case 10:Console .WriteLine(

13、October);break;case 11:Console .WriteLine( November);break;case 12:Console .WriteLine( December); break;default :Console .WriteLine(请重新输入); break;前N项的9、请输入一个代表项数的正整数N (N W 100 ),然后输出1-3+5-7+9-11 +和。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApp

14、lication2 class Programstatic void Main( string args)int n = 0;double sum = 0;Console .Write(请输入一个代表项数的正整数N( N 100 );int a = Convert .ToInt32( Console .ReadLine();for ( int i = 1; i = 90)Console .WriteLine(等级为:A);elseif (90 great & great = 80)Console .WriteLine(等级为:B);elseif (80 great & great = 70)C

15、onsole .WriteLine(等级为:C);elseif (70 great & great = 60)elseConsole .WriteLine(等级为:D);Console .WriteLine(等级为:F不及格);Swich程序using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2class Programstatic void Main( string args)Console .Write(请输入成绩:”);i

16、nt great = Convert .ToInt32( Console .ReadLine(); int x = great / 10;switch (x)case 10:case 9:Console .WriteLine( break;等级为:A);case 8:Console .WriteLine(等级为:B);break;case 7:Console .WriteLine(等级为:C);break;case 6:Console .WriteLine(等级为:D);break;default :Console .WriteLine(等级为:F不及格break;11、读入两个正整数 m和n

17、,输出m和n的最小公倍数。 using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2class Programstatic void Main( string args)Console .WriteLine(计算两个数的最小公倍数 ); Console .Write(请输入第一个数:);int num1 = int .Parse( Console .ReadLine(); Console .Write(请输入第二个数:);int

18、num2 = int .Parse( Console .ReadLine();int gys = gongyue(num1, num2);int gbs = (num1 * num2) / gys; Console .WriteLine(最小公倍数为:+ gbs);static int gongyue( int numl, int num2)int temp = numl % num2;if (temp = 0)return num2;elsereturn gongyue(num2,temp);12、判断一个整数n是否为素数。若是则输出: n是素数;否则输出 n不是素数(注: 具体的值)。us

19、ing System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2class Programstatic void Main( string args)Console .WriteLine(素数的判断。”);Console .Write(请输入一个正整数:”); int num = int .Parse( Console .ReadLine(); int x = 0;for ( int i = 2; i Math.Sqrt(num); i+)i

20、f (num % i = 0)Console .WriteLine(不是素数”);x = i;break;if (x = 0)Console .WriteLine(是素数”);13、用 for 循环计算 s=1!+2!+3!+ +n!。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2class Programstatic void Main( string args)int x = 1;int sum = 0;Consol

21、e .Write(请输入 n = ”);int n = int .Parse( Console .ReadLine();for ( int i = 1; i = n; i+)x = x * i;sum = sum + x;Console .WriteLine( sum = + sum);14、编程实现计算 11+22+33+44+55+ +2020using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2class Programs

22、tatic void Main( string args)double sum = 0;for ( int i = 1; i = 20; i+)sum =Math.Pow(i, i) + sum;Console .WriteLine( sum = + sum);15、编写一个程序,打印出以下图形:*kkk*using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2 class Programstatic void Main( str

23、ing args)for ( int i = 1; i = 3; i +)for ( int j = 1; j = (i * 2) - 1); j = j + 2)Console .Write( *);Console .WriteLine();for ( int i = 1; i = (i * 2) - 1); j = j - 2)Console .Write( *);Console .WriteLine();n (*10 ),实现下列规则图形的输出。16、读入一个代表行数的正整数如果:n=4出. *using System;using System.Collections.Generic;u

24、sing System.Linq;using System.Text;namespace ConsoleApplication2 class Programstatic void Main( string args)n( n= 1; i-)for ( int m = i; m a; m+)Console .Write();for ( int j = 1; j = i * 2 - 1; j+)Console .Write( *);Console .WriteLine();17、请打印由*组成的菱形如下的图形。*1点:*using System;using System.Collections.G

25、eneric;using System.Linq;using System.Text;namespace ConsoleApplication2 class ProgramConsole .Write(输入一个代表行数的正整数n (n10):);int a = int .Parse( Console .ReadLine();for ( int i = 1; i = a; i+)for ( int m = i; m a; m+)Console .Write();for ( int j = 1; j = 1; i-)for ( int m = i; m a; m+)Console .Write()

26、;for ( int j = 1; j = i* 2 - 1; j+)Console .Write(* );Console .WriteLine();100元钱18、百元买百鸡问题。假定小鸡每只5角,公鸡每只2元,母鸡每只3元。现在有要求买100只鸡,编程列出所有可能的购鸡方案。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2 class Programstatic void Main( string args)for (

27、 int num3 = 0; num3 33; num3+)for ( int num2 = 0; num2 50; num2+)for ( int num1 = 0; num1 200; num1+)if (num1 + num2 + num3 = 100 & (5 * numl) + (20 * num2) + (30 * num3)=1000)Console .WriteLine(小鸡有+ numl + 只,公鸡有+ num2 + 只,母 鸡有+ num3 + 只);19、有一条长阶梯,若每步跨 2阶,则最后剩1阶;若每步跨3阶,则最后剩2阶;若每 步跨5阶,则最后剩4阶;若每步跨6阶,

28、则最后剩5阶。只有每次跨7阶,最后才正好 一阶不剩。编写程序算出这条阶梯至少有多少阶?using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2 class Programfor ( int x = 1; x 2fib(1) = fib(2) = 1using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace C

29、onsoleApplication2class Programstatic void Main( string args)Console .Write(请输入 n = ”);int n = int .Parse( Console .ReadLine();int sum = fib(n);Console .WriteLine( fib (+ n +) = + sum);static int fib( int n)if (n = 1 | n = 2)return 1;elsereturn fib(n - 1) + fib(n - 2);21、读入一个正整数 n,判断其是否是回文数,若是则输出:n是

30、回文数;否则输出:n不是回文数。提示:回文数是指这样的自然数,其各位数字顺序读和倒读都一样,例如2,22,121,12321。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2class Programstatic void Main( string args)int s = 0;Console .Write(请输入 n = ”);int n = int .Parse( Console .ReadLine();int y =

31、 n;string x = Convert .ToString(n);int m = x.Length;for ( int t = m-1; t = 0; t-)int w = 0;w = y % 10;y = y / 10;s =(int ) (w * Math.Pow(10, t)+s);Console .Write(s);if (s = n)Console .WriteLine(是回文数”);elseConsole .WriteLine(不是回文数”);22、编程输出下面的杨辉三角。11121133114&411510105120IS17213535usingSystem;using S

32、ystem.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2 class Programstatic void Main( string args)int length = 0;Console .Write(输入杨辉三角长度:”);length =Convert .ToInt32( Console .ReadLine();的一维数组int a = new int length; / 二维数组 a for ( int i = 0; i a.Length; i+)ai =new

33、 int i + 1;/ 遍历,赋值增量for ( int j = 0; j a.Length; j+)aj0 = 1;ajj = 1;for ( int m = 1; m aj.Length - 1; m+) ajm = aj - 1m - 1 + aj - 1m;for ( int i = 0; i a.Length; i+)for ( int j = 0; j ai.Length; j+)Console .Write( 0t, aij);Console .Write( n);Console .Read();23、有一组数据序列45, 23, 1, 2, 67, 3, 8, 56,现要求运

34、用选择排序法和冒泡排序法分别实现按从小到大顺序将它们输出。选择排序法using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication2class Programstatic void Main( string args)int A;A =new int 8 45,23,1,2,67,3,8,56;for ( int i =0;i8;i+)int k = i;for ( int j = i+1;j 8;j+)if ( Aj Ak)k = j;

35、if (k != i)int temp = 0;temp = Ai;Ai = Ak;Ak = temp;for ( int m=0;m dj)temp = di;di = dj;dj = temp;for ( int m = 0;m 8;m+)Console .WriteLine(dm +);24、若一本书厚250页,每页20行,每行40个字符。假设全书的内容已经存入了三维数组 变量book中,其下标为page line和column。要求编写程序在屏幕上输出任意指定的连续 几页上的内容(即从某起始页 startp显示至某结束页 en dp)。using System;using System

36、.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3class Programint , , book = new int 250, 20, 40;Console .Write(输入开始页码:startp=);int startp = int .Parse( Console .ReadLine();Console .Write(请输入结束页码:endp=);int endp = int .Parse( Console .ReadLine();for ( int page =

37、0; page 250; page+)for ( int line = 0; line 20; line+)for ( int column = 0; column 40; column+)bookpage, line, column = column;for ( int page = startp-1; page = endp; page+)for ( int line = 0; line 20; line+)for ( int column = 0; column 40; column+)Console .Write(bookpage, line, column);25、给定一串正实数数列

38、,求出所有递增和递减子序列的数目,如数列7.34、2.2、6.8、9.09、8.81、3、5.2、2.3、1.8,则可以分为(7.34、2.2),( 2.2、6.8、9.09),(9.09、8.81、3),( 3、5.2),( 5.2、2.3、1.8)五个子序列,答案就是5。现在要求随机产生10个正实数的数列,然后进行处理,最后输出答案,请编程实现。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3class Program

39、static void Main( string args)int x = 0,0,0,0,0,0,0,0;double s = 7.34,2.2,6.8,9.09,8.81,3,5.2,2.3,1.8;for ( int i = 0; i si + 1)xi = 1;else if (si si+1)xi = 2;for ( int i = 0; i x.Length; i+)Console .Write(xi +);Console .WriteLine();for ( int i = 0; i x.Length - 1; i+)if (xi != xi + 1)Console .Write

40、(si + si + 1);Console .WriteLine();else if (xi = xi + 1)Console .Write(si + si + 1 + si + 2);Console .WriteLine();i = i + 1;若是则输出:26、编写程序实现功能:输入两个字符串s1和s2 ,判断s2是否是s1的子串,1,n (n是s2在s1字符串中的起始位置);若不是则输出:0。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Console

41、Application3class Programstatic void Main( string args)Console .Write(请输入字符串 si =);string si = Console .ReadLine();Console .Write(请输入字符串 s2 =);string s2 = Console .ReadLine();int i = 0;if (s2.Contains(s1) & sl.Length = s2.Length) i = s1.IndexOf(s2);Console .WriteLine( 1 + + (i + 1);elseConsole .Writ

42、eLine( 0);27、编写程序实现功能:已知一个英语单词串”am a student ”统计其中的单词个数(单词间用空格分隔),并输出单词个数与每个单词(一行一个单词)。using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3 class Programstatic void Main( string args)Console .Write(请输入一个字符串 s =);string s = Console .ReadLine(

43、);string s2 = s.Split( );for ( int i = 0; i s2.Length; i+)Console .WriteLine(s2i);Console .WriteLine(共有单词+(s2.Length)+ 个);28、计算机在教育中的作用越来越大。编写一程序帮助小学生学习乘法。利用随机数方法产生两个正的一位整数,并显示出题目,如:6乘3的积是多少?学生在文本框中输入结果。程序检查该学生的答案,如果答案正确,打印出“非常棒” 并再出一道题。如果答案错误,打印字符串“不对,请再试一次。”再让学生重做该题,直到做对为止。利用一个方法来产生题目。using System

44、;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication3class Programstatic void Main( string args)Randomran = new Randon(i);int x = ran.Next(0, 10);int y = ran.Next(0, 10);Console .Write(x +x + y +=);int z = int .Parse( Console .ReadLine();while (z != (x * y)Console .WriteLine(不对,请再试一次”);Console .Write(x +x + y +=);z =int .Parse( Console .ReadLine();if (z = (x * y)Console .WriteLine(非常棒);29、复杂的计算机辅助教学系统可以监测学生在一段时间内的表现。修改习题28中的程序累计回答问题的正确和错误次数。在学生回答10个问题后,程序计算出回答问题的正确率,若低于75%,程序应打印出“请你的老师给你辅导一下”。using System;using System.Collections.Generic;using Sys

温馨提示

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

评论

0/150

提交评论