C语言上机题目1及答案.doc_第1页
C语言上机题目1及答案.doc_第2页
C语言上机题目1及答案.doc_第3页
C语言上机题目1及答案.doc_第4页
C语言上机题目1及答案.doc_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

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

文档简介

C#语言上机题目实验一 C#基础1. 编一个程序,定义常量Pi=3.14159265,从键盘上输入半径r,求出圆的面积。2.编一个程序,从键盘上输入三个数,用三元运算符(? :)把最大数找出来。3.编一个程序,输入一个字符,如果是大写字母,就转换成小写字母,如果输入的字符是小写字母,则转换为大写字母,否则不转换。4.输入一个字符,判定它是什么类型的字符(大写字母,小写字母,数字或者其它字符)5.编一个程序,定义一个实数变量,从键盘上输入一个值,如果这个值在闭区间0,100里,则加上1000,否则不加。最后输出结果。6.编一个程序,输入一个正数,对该数进行四舍五入到个位数的运算。例如,实数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之和。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 = 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.WriteLine(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 (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 (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=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个,大写: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(); 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; 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 (

温馨提示

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

评论

0/150

提交评论