c#程序.docx
- 文档编号:13918086
- 上传时间:2023-06-19
- 格式:DOCX
- 页数:21
- 大小:76.27KB
c#程序.docx
《c#程序.docx》由会员分享,可在线阅读,更多相关《c#程序.docx(21页珍藏版)》请在冰点文库上搜索。
c#程序
1、开发一个控制台应用程序,使之输出字符串“北京欢迎你!
”。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespacetest01
{
classProgram
{
staticvoidMain(string[]args)
{
Console.WriteLine("北京欢迎你!
");
}
}
}
1、开发一个控制台应用程序,根据提示从键盘输入圆的半径,随后输出圆的面积和周长。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespacetest02
{
classProgram
{
staticvoidMain(string[]args)
{
Console.WriteLine("请输入圆的半径");
stringstr=Console.ReadLine();
doubler=Double.Parse(str);
doubles=Math.PI*r*r;
Console.WriteLine("圆的面积是{0:
f2}",s);
}
}
}
1、开发一个控制台应用程序,根据提示从键盘获取一个摄氏温度,请转换并输出对应的华氏温度。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespacetest03
{
classProgram
{
staticvoidMain(string[]args)
{
Console.WriteLine("请输入摄氏温度:
");
floats=float.Parse(Console.ReadLine());
floatc=9*s/5+32;
Console.WriteLine("输入摄氏温度{0}转换成的华氏温度{1:
f2}",s,c);
}
}
}
1、开发一个控制台应用程序,根据提示从键盘输入一个字符,判断此字符是数字、大写字母、小写字母还是其它字符。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespacetest04
{
classProgram
{
staticvoidMain(string[]args)
{
Console.WriteLine("请输入要判断字符");
intc=Console.Read();
if(c>='0'&&c<='9')
Console.WriteLine("该字符为数字");
else
if(c>='A'&&c<='Z')
Console.WriteLine("该字符为大写字母");
else
if(c>='a'&&c<='z')
Console.WriteLine("该字符为小写字母");
else
Console.WriteLine("该字符为其他字符");
}
}
}
1、编写一个C#控制台应用程序,从键盘输入年份,判断此年份是不是闰年。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespacetest05
{
classProgram
{
staticvoidMain(string[]args)
{
Console.WriteLine("请输入要判断的年份");
intyear=int.Parse(Console.ReadLine());
if((year%4==0&&year%100!
=0)||year%400==0)
Console.WriteLine("{0}年为闰年",year);
else
Console.WriteLine("{0}年为平年",year);
}
}
}
2、设计一个控制台应用程序,输入任意字符串,统计其中元音字母('a','e','i','o','u',不区分大小写)出现的次数及频率。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespacetest01
{
classProgram
{
staticvoidMain(string[]args)
{
intcountA=0,countE=0,countI=0,countO=0,countU=0;
Console.WriteLine("请输入字符串");
Strings=Console.ReadLine();
s=s.ToUpper();
char[]c=s.ToCharArray();
foreach(charchinc)
{
switch(ch)
{
case'A':
countA++;
break;
case'E':
countE++;
break;
case'I':
countI++;
break;
case'O':
countO++;
break;
case'U':
countU++;
break;
default:
break;
}
}
Console.WriteLine("A出现频数为{0},频率为{1:
P2}",countA,countA*0.1/s.Length);
Console.WriteLine("E出现频数为{0},频率为{1:
P2}",countE,countE*0.1/s.Length);
Console.WriteLine("I出现频数为{0},频率为{1:
P2}",countI,countI*0.1/s.Length);
Console.WriteLine("O出现频数为{0},频率为{1:
P2}",countO,countO*0.1/s.Length);
Console.WriteLine("U出现频数为{0},频率为{1:
P2}",countU,countU*0.1/s.Length);
}
}
}
2、设计一个控制台应用程序,定义一个拥有3行4列的矩形数组,数组元素值随机生成,取值范围是[1,50],在控制台打印出此数组元素。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespacetest02
{
classProgram
{
staticvoidMain(string[]args)
{
int[,]a=newint[3,4];
Randomr=newRandom();
for(inti=0;i<3;i++)
{
for(intj=0;j<4;j++)
{
a[i,j]=r.Next(1,51);
Console.Write("{0,5}",a[i,j]);
}
Console.WriteLine();
}
}
}
}
2、设计一个控制台应用程序,定义一个拥有3个元素的二维交错整型数组。
三个元素长度分别是5、4、3,元素值随机生成,取值范围[50,100]。
在控制台打印出此数组元素。
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespacetest03
{
classProgram
{
staticvoidMain(string[]args)
{
int[][]a=newint[3][];
a[0]=newint[5];
a[1]=newint[4];
a[2]=newint[3];
Randomr=newRandom();
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c# 程序