2007年3月16日 第一次pascal试验课 上机内容是顺序结构程序设计
以下是我课上写的几段代码,文件名就是课本上题目的位置,例如P14_1_2.PAS即为第14页的习题1.2。
P14_1_2.PAS
PROGRAM count(input,output);
{输入三个数,计算并输出它们的平均值及乘积}
VAR
num1,num2,num3,average,product:real;
BEGIN
write( ' please input three numbers: ' );
readln(num1,num2,num3);
{计算这三个数的平均值}
average: = (num1 + num2 + num3) / 3 ;
{计算这三个数的乘积}
product: = (num1 * num2 * num3);
{进行回打并输出其平均数和乘积}
writeln;
writeln( ' the numbers you input is ' ,num1: 4 : 2 , ' ' ,num2: 4 : 2 , ' ' ,num3: 4 : 2 );
writeln( ' the average is ' ,average: 4 : 2 , ' ;the product is ' ,product: 4 : 2 )
END.
{输入三个数,计算并输出它们的平均值及乘积}
VAR
num1,num2,num3,average,product:real;
BEGIN
write( ' please input three numbers: ' );
readln(num1,num2,num3);
{计算这三个数的平均值}
average: = (num1 + num2 + num3) / 3 ;
{计算这三个数的乘积}
product: = (num1 * num2 * num3);
{进行回打并输出其平均数和乘积}
writeln;
writeln( ' the numbers you input is ' ,num1: 4 : 2 , ' ' ,num2: 4 : 2 , ' ' ,num3: 4 : 2 );
writeln( ' the average is ' ,average: 4 : 2 , ' ;the product is ' ,product: 4 : 2 )
END.
P14_1_3.PAS
PROGRAM count(input,output);
{计算并打印地球的表面积和体积,已知地球半径为6371km}
CONST
pi = 3.14159 ;
VAR
r,s,v:real;
BEGIN
r: = 6371 ;
{计算地球表面积}
s: = 4 * pi * r * r;
{计算地球体积}
v: = 4 / 3 * pi * sqr(r) * r;
{打印地球表面积和体积}
writeln( ' the acreage of the earth is ' ,s: 2 : 2 , ' km2 ' , ' and the volume of the earth is ' ,v: 2 : 2 , ' km3. ' )
END.
{计算并打印地球的表面积和体积,已知地球半径为6371km}
CONST
pi = 3.14159 ;
VAR
r,s,v:real;
BEGIN
r: = 6371 ;
{计算地球表面积}
s: = 4 * pi * r * r;
{计算地球体积}
v: = 4 / 3 * pi * sqr(r) * r;
{打印地球表面积和体积}
writeln( ' the acreage of the earth is ' ,s: 2 : 2 , ' km2 ' , ' and the volume of the earth is ' ,v: 2 : 2 , ' km3. ' )
END.
P14_1_4.PAS
PROGRAM count(input,output);
{已知初速度和加速度,计算末速度,位移和平均速度}
CONST
v0 = 10 ;
a = 2 ;
t = 20 ;
VAR
v1,s,v:real;
BEGIN
{计算末速度}
v1: = v0 + a * t;
{计算位移}
s: = v0 * t + 1 / 2 * a * t * t;
{计算平均速度}
v: = s / t;
{打印末速度,位移,以及平均速度}
writeln( ' the velocity of the end is ' ,v1: 2 : 2 , ' m/s ' );
writeln( ' the displacement is ' ,s: 2 : 2 , ' m ' );
writeln( ' the average velocity is ' ,v: 2 : 2 , ' m/s ' )
END.
{已知初速度和加速度,计算末速度,位移和平均速度}
CONST
v0 = 10 ;
a = 2 ;
t = 20 ;
VAR
v1,s,v:real;
BEGIN
{计算末速度}
v1: = v0 + a * t;
{计算位移}
s: = v0 * t + 1 / 2 * a * t * t;
{计算平均速度}
v: = s / t;
{打印末速度,位移,以及平均速度}
writeln( ' the velocity of the end is ' ,v1: 2 : 2 , ' m/s ' );
writeln( ' the displacement is ' ,s: 2 : 2 , ' m ' );
writeln( ' the average velocity is ' ,v: 2 : 2 , ' m/s ' )
END.
P14_1_5.PAS
PROGRAM count(input,output);
{输入摄氏度并将其转换成华氏度}
VAR
f,c:real;
BEGIN
{读入摄氏温度}
read(c);
{将摄氏度转换成华氏度}
f: = 9 / 5 * c + 32 ;
{打印华氏度}
writeln( ' the Fahrenheit is ' ,f: 2 : 2 , ' F ' );
END.
{输入摄氏度并将其转换成华氏度}
VAR
f,c:real;
BEGIN
{读入摄氏温度}
read(c);
{将摄氏度转换成华氏度}
f: = 9 / 5 * c + 32 ;
{打印华氏度}
writeln( ' the Fahrenheit is ' ,f: 2 : 2 , ' F ' );
END.
P37_2_4.PAS
PROGRAM triangle(input,output);
{通过三角形的三边长度计算三角形面积}
VAR
a,b,c,p,s:real;
BEGIN
write( ' 请输入三角形的三个边长: ' );
read(a,b,c);
writeln( ' 您输入的三个边长分别为: ' , ' a= ' ,a: 4 : 2 , ' b= ' ,b: 4 : 2 , ' c= ' ,c: 4 : 2 );
p: = (a + b + c) / 2 ;
s: = sqrt(p * (p - a) * (p - b) * (p - c));
writeln( ' 此三角形的面积 s= ' ,s: 4 : 2 )
END.
{通过三角形的三边长度计算三角形面积}
VAR
a,b,c,p,s:real;
BEGIN
write( ' 请输入三角形的三个边长: ' );
read(a,b,c);
writeln( ' 您输入的三个边长分别为: ' , ' a= ' ,a: 4 : 2 , ' b= ' ,b: 4 : 2 , ' c= ' ,c: 4 : 2 );
p: = (a + b + c) / 2 ;
s: = sqrt(p * (p - a) * (p - b) * (p - c));
writeln( ' 此三角形的面积 s= ' ,s: 4 : 2 )
END.
P37_2_5.PAS
PROGRAM printy(input,output);
{通过公式计算打印y值}
CONST
pi = 3.14159 ;
VAR
x,y:real;
BEGIN
x: = sqrt( 1 + sin( 52.25 * pi / 180 ) / cos( 52.25 * pi / 180 ));
y: = exp(pi / 2 * x) + ln(abs(sin(x) * sin(x) - sin(x * x)));
writeln( ' y= ' ,y: 1 )
END.
{通过公式计算打印y值}
CONST
pi = 3.14159 ;
VAR
x,y:real;
BEGIN
x: = sqrt( 1 + sin( 52.25 * pi / 180 ) / cos( 52.25 * pi / 180 ));
y: = exp(pi / 2 * x) + ln(abs(sin(x) * sin(x) - sin(x * x)));
writeln( ' y= ' ,y: 1 )
END.
2007年4月8日 sch