C#程序设计实验报告
- 格式:docx
- 大小:41.02 KB
- 文档页数:20
int a, b, c, a1, b1, c1, t, Nmax, Nmin, Nmid;
Ran dom rMun = new Ran dom();
a = (101);
b = (101);
c= (101);
(”原始值:a={0},b={1},c={2}",a,b,c);
al=a; bl = b; cl = c;
s =();
b = (s);
("请输入三角形的边c:");
s =();
c = (s);
if (a > 0 && b > 0 && c > 0 && a+b > c && a+c > b && b+c > a) {
("三角形三边分别为:a={0},b={1},c={2}",a,b,c);
p = a+b+c;
Console .WriteLine ("方法二:x={0},y={1}",x,y);
if(x>=0)
y = (x * x-ห้องสมุดไป่ตู้ * x)/(x+1)+2 *+(x);
else
y=(-5*x)+6*Math .Sqrt(Math .Abs (x)+Math .Pow (Math .E,4)-Math Pow
(x+1,3));
Console .WriteLine ("方法三:x={0},y={1}",x,y);
y=(x>=0)?(x * x-3 * x)/(x+1)+2 *+(x):(-5*x)+6*Math .Sqrt (Math .Abs
(x)+Math .Pow (Math .E,4)-Math .Pow (x+1,3));
{
class Program
{
static void Main(string[] args)
{
double x, y;
Con sole .Write ("请输入x:");
stri ng s =();
x = (s);
y = (x * x-3 * x)/(x+1)+ 2*+(x);
if(x<0)
y=(-5*x)+6*Math .Sqrt (Math .Abs (x)+Math .Pow ,4)-Math .Pow (x+1,3));
Visual Studio 2005
五、实验步骤、结果(或记录) 实验二
2-1输入半径,求对应的圆的周长、面积、对应球体的体积。
运行结果:
圆的周凭®・4佔J圆的画积=78.53975球体的体积=392.£9875
实验代码:
using System; usi ng ;
usi ng ;
n amespace _2_1
if (a > b)
{
t = a; a = b; b = t;
}
if (a > c)
{
t = a; a = c; c = t;
}
if (b > c)
{
t = b; b = c; c = t;
}
(("(方法一)升序值:a={0},b={1},c={2}"),a,b,c);
a = a1; b = b1; c = c1;
Con sole .WriteLi ne ("方法四:x={0},y={1}",x,y);
Con sole .ReadKey ();
}
}
}
2-4
运行结果:
实验代码:
using System;
usi ng ;
usi ng ;
n amespace _2__4
{
class Program
{
static void Main(string[] args)
{
class Program
{
static void Main(string[] args)
{
const double PI =;
double r, perimeter, area, volume;
("请输入半径:”);
Stri ng s =();
r = (s);
("圆的半径为={0}",r);
perimeter = 2 * PI * r; area = PI * r * r;
运行结果:
实验代码:
using System;
usi ng ;
n amespace Con sole2_5 {
class Program
{
static void Main(string[] args)
{
double a, b, c, delta, x1, x2, realPart, imagePart;
姓名
专业
软件工程
课程名 称
C#程序设计
、实验名称:
实验2
二、
掌握使用命令行开发简单的
掌握Visual Studio环境下程序的跟踪调试
了解Visual Studio在线帮助的使用
掌握应用程序命令行参数的使用
三、
利用完成数据的增、删、改、查
四、实验材料、工具、或软件
Win dows XP Professio nal SP3
volume = 4/3 * PI * (r, 3);
("圆的周长为={0},面积为={1}",perimeter ,area );
("球体的体积={0}",volume);
();
}
}
}
2-2
stri ng s =();
a = (s);
Co nsole .Write ("请输入三角形的边b:");
("请输入系数a:");
Stri ng s =();
a = (s);
("请输入系数b:");
s =();
Nmax =Math .Max (Math .Max (a,b),c);
Nmin = (a, b), c);
Nmid = a+b+c-Nmax-Nmi n;
a = Nmi n;
b = Nmid;
c = Nmax;
("(方法二)升序值:a={0},b={1},c={2}",a,b,c);
();
}
}
}
2-5
h = p/2;
area = (h * (h-a) * (h-b) * (h-c));
("三角形的周长={0},面积为={1}",p,area);
}
else ("无法构成三角形!”);
();
}
}
}
2-3
运行结果
实验代码:
using System;
usi ng ;
usi ng ;
n amespace _2_3_2
Console .WriteLine ("方法一:x={0},y={1}",x,y);
if(x>=0)
y = (x * x-3 * x)/(x+1)+2 *+(x);
if(x<0)
y=(-5*x)+6*Math.Sqrt (Math .Abs (x)+Math .Pow ,4)-Math Pow (x+1,3));