1.输入年份,月份,天,判断这个日期是否正确?
2.输入年份,月份显示这个月有多少天?
1staticvoidMain(string[]args)2{3Console.Write("请输入年份:");4intyear=Convert.ToInt32(Console.ReadLine());5Console.Write("请输入月份:");6intmonth=Convert.ToInt32(Console.ReadLine());78if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)9{10Console.WriteLine("本月是31天");11}12elseif(month==4||month==6||month==9||month==11)13{14Console.WriteLine("本月是30天");15}16elseif(month==2)17{18if(year%400==0||(year%4==0&&year%100!=0))19{20Console.WriteLine("29天");21}22else23{24Console.WriteLine("28天");25}26}27else28{29Console.WriteLine("月份有问题");30}31}
3.axx+bx+c==0(a!=0)。输入a,b,c给这个一元二次方程,显示根的个数?
1staticvoidMain(string[]asdfasdf)2{3Console.WriteLine("一元二次方程a*x*x+b*x+c==0,请输入a,b,c的值");4inta=Convert.ToInt32(Console.ReadLine());5intb=Convert.ToInt32(Console.ReadLine());6intc=Convert.ToInt32(Console.ReadLine());78if(a==0)9{10Console.WriteLine("不是一元二次方程");11}12else13{14intdelta=b*b-4*a*c;15if(delta>0)16{17Console.WriteLine("两个不等实根");18}19elseif(delta==0)20{21Console.WriteLine("两个相等实根");22}23else24{25Console.WriteLine("无实根");26}27}28}
4.男士身高与体重的关系是:身高-100=体重;女士:身高-110=体重。(自己试着做)上下浮动3公斤属正常。输入性别,身高,体重,输出:正常?偏胖?偏瘦?
1staticvoidMain(string[]args)2{3stringxingbie;4intshengao,tizhong;56//输入:7Console.Write("性别:");8xingbie=Console.ReadLine();9Console.Write("身高:");10shengao=Convert.ToInt32(Console.ReadLine());11Console.Write("体重:");12tizhong=Convert.ToInt32(Console.ReadLine());1314//运算15if(xingbie=="男")16{17intnbz=shengao-100;//标准体重18if(nbz-tizhong>=-3&&nbz-tizhong<=3)19{20Console.WriteLine("正常,请继续保持");21}22elseif(nbz-tizhong<-3)23{24Console.WriteLine("偏胖,请意饮食");25}26else27{28Console.WriteLine("偏瘦,注意营养");29}30}31elseif(xingbie=="女")32{33intvbz=shengao-110;//标准体重34if(vbz-tizhong>=-3&&vbz-tizhong<=3)35{36Console.WriteLine("正常,请继续保持");37}38elseif(vbz-tizhong<-3)39{40Console.WriteLine("偏胖,请意饮食");41}42else43{44Console.WriteLine("偏瘦,注意营养");45}46}47else48{49Console.WriteLine("只能识别人类");50}5152}
5.做一个跟计算机猜拳的小游戏。0-剪刀,1-石头,2-布要求输出0,1,2,计算机生成随机数,与人类输入的相比较判断谁胜了。计算机生成随机数:Randomrand=newRandom();intc=rand.Next(3);
6.做一个算缘分的小游戏:输入男方姓名,女方姓名,输出缘分指数,给出建议。
1staticvoidMain(string[]args)2{3Console.Write("男方姓名:");4stringnan=Console.ReadLine();5Console.Write("女方姓名:");6stringnv=Console.ReadLine();78Randomrand=newRandom();9intn=rand.Next(100);10n++;1112stringjianYi="";13if(n>0&&n<30)14{15jianYi="分手吧";16}17elseif(n>=30&&n<60)18{19jianYi="一起努力";20}21elseif(n>=60&&n<=80)22{23jianYi="幸福一对";24}25else26{27jianYi="鸳鸯配";28}2930Console.WriteLine("{0}和{1}的缘分指数是:{2}。建议:{3}",nan,nv,n,jianYi);31}