《C#语言上机题目1及答案(7页).doc》由会员分享,可在线阅读,更多相关《C#语言上机题目1及答案(7页).doc(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、-C#语言上机题目1及答案-第 7 页C#语言上机题目实验一 C#基础1. 编一个程序,定义常量Pi=3.14159265,从键盘上输入半径r,求出圆的面积。2.编一个程序,从键盘上输入三个数,用三元运算符(? :)把最大数找出来。3.编一个程序,输入一个字符,如果是大写字母,就转换成小写字母,如果输入的字符是小写字母,则转换为大写字母,否则不转换。4.输入一个字符,判定它是什么类型的字符(大写字母,小写字母,数字或者其它字符)5.编一个程序,定义一个实数变量,从键盘上输入一个值,如果这个值在闭区间0,100里,则加上1000,否则不加。最后输出结果。6.编一个程序,输入一个正数,对该数进行四
2、舍五入到个位数的运算。例如,实数12.56经过四舍五入运算,得到结果13;而12.46经过四舍五入运算,得到结果12。7.编写一个程序,定义三个float类型的变量,分别从键盘上输入值给它们, 然后用if else选择语句找出它们中的最小数,最后输出结果。8. 编一个程序,首先输入一个成绩(0到100的整数),分别用if else语句和Switch语句判断该成绩是优、良、中、及格还是不及格,如果是100分还需输出时满分。9.编一个程序,利用do-while循环语句,从键盘上输入10个整数,求出它们的和。10. 编一个程序,用while循环语句来计算1+1/2+2/3+3/4+.+99/100之
3、和。11.编一个程序,打印出所有的“水仙花数”,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如, 153=1*1*1+5*5*5+3*3*3,所以153是“水仙花数”12. 有关系式1*1+2*2+3*3+.+k*k b ? a : b; k = k c ? k : c; Console.WriteLine(0,1,2最大的为3,a,b,c,k); public static void T3() char x = Convert.ToChar(Console.Read(); int a = A; int b = a; if (x = a & x =A&x= 0 & x =
4、a & x = A & x = 0 & a b) a = b; if (a c) a = c; Console.WriteLine(0,a); public static void T8() double a = Convert.ToDouble(Console.ReadLine(); if (a = 100) Console.WriteLine(100fen); else if (a = 90) Console.WriteLine(youxiu); else if (a = 80) Console.WriteLine(lianghao); else if (a = 70) Console.W
5、riteLine(zhongdeng); else if (a = 60) Console.WriteLine(jige); else Console.WriteLine(bujige); public static void T9() int sum = 0; int i = 1; do int a = Convert.ToInt32(Console.ReadLine(); sum += a; i+; while (i 0) sum += (i-1)0?i-1:1) / i; i-; Console.WriteLine(0,sum); public static void T11() for
6、 (int i = 100; i 1000; +i) int a = i % 10; int b = i / 100; int c = (i / 10) % 10; if (a * a*a + b * b*b + c*c * c = i) Console.WriteLine(0,i); public static void T12() for (int i = 1; i = 2000; +i) int sum = 0; for (int j = 1; j = 2000) Console.WriteLine(0,i-1); return; public static void T13() for
7、 (int i = 1; i = 9; +i) for (int j = 1; j = i; +j) Console.Write(0*1=2 ,i,j,i*j); Console.WriteLine(); public static void T14() int x, y, z; for (x = 0; x = 100; +x) for (y = 0; y = 100; +y) for (z = 0; z = 100; +z) if (x + y + z = 100 ) if(z%3=0 & 5 * x + 3 * y + z / 3 = 100)Console.WriteLine(x=0,y
8、=1,z=2,x,y,z); public static void T15() int a = new int100; int p = 0; for(int i = 0;i 10; +i) int x = Convert.ToInt32(Console.ReadLine(); int judge = p; for(int j = 0;j x) judge = j; break; p+; for(int j = p-1;j judge; -j) aj = aj-1; ajudge = x; for(int j = 0;j =a&c=A&c=Z)b+; Console.WriteLine(小写:0
9、个,大写:1个,a,b); public static void T17() String str1 = Console.ReadLine(); char str2 = new char100; int i = 0; foreach (char x in str1) str2i+ = x; str2i = 0; for(int j = 0;j i; +j) Console.Write(0,str2j); Console.WriteLine(); public static void T18() int vis = new int30; string str = Console.ReadLine
10、(); for (int i = 0; i str.Length; +i) int x = 0; if (visstri - a = 0) for (int j = i + 1; j 0) Console.WriteLine(0重复出现1次, stri, x); visstri - a+; public static void MaxminArray(int num,ref int x,ref int y) x = num0; y = num0; foreach (int a in num) if (x a) y = a; public static void T19() int x = 0;
11、 int y = 0; int num=-1,1,2,3,5; MaxminArray(num,ref x,ref y); Console.WriteLine(max=0,min=1,x,y); public static void SortArray(int num, bool flag) for (int i = 0; i num.Length; +i) for (int j = i + 1; j numj) = flag) int t = numi; numi = numj; numj = t; public static void T20() int num = -1, 1, 2, 3, 5 ,10, -2, 15; SortArray(num, false); foreach (int x in num) Console.Write(0 , x); Console.WriteLine(); SortArray(num, true); foreach (int x in num) Console.Write(0 , x); Console.WriteLine(); static void Main(string args)