c#实训基础题部分

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

使用控制台方式实现如下应用程序:基础题部分:1、写一个程序,完成以下功能:从键盘上输入5个整数,求出最大最小值。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){Console.Write(pleaseenter5figure:);double[]a=newdouble[5];for(inti=0;i5;i++){a[i]=int.Parse(Console.ReadLine());}doublemin=a[0];doublemax=a[0];for(intj=0;j4;j++){if(maxa[j+1]){max=a[j+1];}}Console.WriteLine(max=+max);for(intp=0;p4;p++){if(mina[p+1]){min=a[p+1];}}Console.WriteLine(min=+min);}}}2、写一个程序,打印出九九乘法表。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){for(inti=1;i10;i++){for(intj=1;ji+1;j++){Console.Write(+i+X+j+=+(i*j));}Console.WriteLine();}}}}3、分别使用for循环和while循环设计一个程序,计算从1加到100的和。For循环:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){intsum=0;for(inti=1;i=100;i++){sum=sum+i;}Console.WriteLine(sum=+sum);}}}While循环:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){intsum=0;inti=1;while(i=100){sum=sum+i;i++;}Console.WriteLine(sum=+sum);}}}4、利用数学类提供的平方根方法计算并输出1.0,2.0,3.0,…,10.0的平方根。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){doublex=0.0;for(doublei=1.0;i=10.0;i=i+1){x=Math.Sqrt(i);Console.WriteLine(i+^2=+x);}}}}5、随机数方法产生5个1~10(包括1和10)之间的整数。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){for(inti=0;i5;i++){Randomran=newRandom(i);intRandomkey=ran.Next(1,10);Console.WriteLine(Randomkey);}}}}6、编程实现:随机产生1~20之间的整数,总共生成1000次,统计其中生成的整数0,1,2,3,...…,20的个数分别是多少,并输出统计结果(每5个数一行)。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){int[]A;A=newint[21];for(inti=0;i1000;i++){Randomran=newRandom(i);intRandomkey=ran.Next(0,20);intx=Randomkey;A[x]++;}for(intj=0;j20;j++){Console.Write(A[j]+);if((j+1)%5==0)Console.WriteLine();}}}}7、统计字符串“a12bcd?A*B34”中分别有多少个数字和字母。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){intnum=0;intalpha=0;Strings=a12bcd?A*B34;for(inti=0;is.Length;i++){Stringch=s.Substring(i,1);if(char.IsNumber(ch,0)){num++;}elseif(char.IsUpper(ch,0)||char.IsLower(ch,0)){alpha++;}}Console.WriteLine(num=+num+,alpha=+alpha);}}}8、编写程序,要求用户输入月份号码,然后显示该月的英文名称。例如,如果用户输入2,程序应显示February。要求月的英文名称存于数组中。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication1{classProgram{staticvoidMain(string[]args){//string[]month=newstring[12];//month=(January,February,March,April,May,June,July,August,September,October,November,December);Console.Write(请输入您要的月数:);stringa=Convert.ToString(Console.ReadLine());switch(a){case1:Console.WriteLine(January);break;case2:Console.WriteLine(February);break;case3:Console.WriteLine(March);break;case4:Console.WriteLine(April);break;case5:Console.WriteLine(May);break;case6:Console.WriteLine(June);break;case7:Console.WriteLine(July);break;case8:Console.WriteLine(August);break;case9:Console.WriteLine(September);break;case10:Console.WriteLine(October);break;case11:Console.WriteLine(November);break;case12:Console.WriteLine(December);break;default:Console.WriteLine(请重新输入);break;}}}}9、请输入一个代表项数的正整数N(N≤100),然后输出1-3+5-7+9-11+……前N项的和。usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication2{classProgram{staticvoidMain(string[]args){intn=0;doublesum=0;Console.Write(请输入一个代表项数的正整数N(N≤100):);inta=Convert.ToInt32(Console.ReadLine());for(inti=1;i=a;i=i+2,n++){sum=((Math.Pow(-1,n))*i)+sum;}Console.WriteLine(sum=+sum);}}}10、请编写两个程序,分别通过if语句和switch语句两种方式完成,输入一个成绩,将百分制成绩转换成等级制成绩(A为100~90,…,F为不及格)。If程序usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication2{classProgram{staticvoidMain(string[]args){Console.Write(请输入成绩:);doublegreat=Convert.ToDouble(Console.ReadLine());if(great=90)Console.WriteLine(等级为:A);elseif(90great&&great=80)Console.WriteLine(等级为:B);elseif(80great&&great=70)Console.WriteLine(等级为:C);elseif(70great&&great=60)Console.WriteLine(等级为:D);elseConsole.WriteLine(等级为:F不及格);}}}Swich程序usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceConsoleApplication2{classProgram{staticvoidMain(string[]args){Console.Write(请输入成绩:);intgreat=Convert.ToInt32(Console.ReadLine());intx=great/10;switch(x){case10:case9:Console.WriteLine(等级为:A);break;case8:Console.WriteLine(等级为:B);break;case7:Console.WriteLine(等级为:C);break;case6:Console.WriteLine(等级为:D);break;default:Console.WriteLine(等级为:F不及格);break;}}}}11、读入两个正整数m和n,输出m和n的最小公倍数。usingSystem;usingSy

1 / 44
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功