Pascal程序设计(二级)——基础篇05格式化输入输出

主要研究了格式化输入输出的有趣现象!
摘要由CSDN通过智能技术生成

大家好,我们接着Pascal2010语言特性的研讨,对于一门语言,进行详细的研究是必要的,因为各种语言的特点或者说特性都是各有千秋的,详细的了解语言特性是对我们编程有很大帮助的,俗话说得好,“磨刀不误砍柴工”就是这个理,就像我们学习英语类似,我们从小学到大学都学了很多年,我们的Pascal语言花一番功夫详细彻底的研究同样也是需要的。。。

好,转回今天的正题,对于格式化输入输出,很多人并不陌生,但是又仿佛不能像C一样说的那么简洁透彻,那么就让我们先从下面的具体的计算问题研究,注意这里关于各种常用数据的表示,自行学习参考资料,还有例题中要用到的Format函数,不熟悉的自行上网搜寻学习,这里不重码了。。。

好,瞧例题,这个例题是关于一个近代物理实验的计算题,知道怎么回事的,可以详细了解习题,感觉有点陌生的,可以只关注最后的数学计算式就行了,我们主要是借这个题研究格式输入输出的。。。(这种方法论在中学中,大家也不陌生了,叫关注主要因素,忽略次要因素!!微笑



给出程序:

program Ag原子速度;


{$APPTYPE CONSOLE}


uses
  SysUtils;


var
  v:real;


begin

  //注意科学计数法的写法规则
  v:=0.1*sqrt(((9.274e-24)*60)/((0.15e-3)*(1.79e-25)));
  writeln('Ag原子速度是',v);

  //writeln可以直接调用format函数的!~
  writeln(format('%s%f',['Ag原子速度是',v]));
  { %f 表示浮点数, 保留或凑够两位小数点 }
  writeln('Ag原子速度是',format('%f',[v]));


  { %g 表示浮点数, 会去掉多余的 0 }
  writeln('Ag原子速度是',format('%g',[v]));


  { %e 用科学计数法表示整数或浮点数 }
  writeln('Ag原子速度是',format('%e',[v]));


  { %x 用十六进制表示一个整数 }
//  writeln('Ag原子速度是',format('%x',[v]));
//这里不能用16进制输出,否则在运行时中断


  { 指定小数点的位数, 取值范围1-9, 输入0也当1用 }
  writeln('Ag原子速度是',format(&

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
超强大、好用的Pascal语言解释器:RemObjects Pascal Script,支持以下特性: Pascal Script is a widely-used set of components for Delphi that makes it easy to add Pascal-based scripting support to your applications, so that they can extend or control your application with custom scripts. Get Pascal Script Free Now Start using Pascal Script now and download your free copy, including full source code. Pascal Script for Delphi Pascal Script is a free scripting engine that allows you to use most of the Object Pascal language within your Delphi or Free Pascal projects at runtime. Written completely in Delphi, it is composed of a set of units that can be compiled into your executable, eliminating the need to distribute any external files. Pascal Script started out as a need for a good working script, when there were none available at the time. Why use a scripting engine? A scripting engine allows an end user to customize an application to his or her needs without having to recompile it. In addition, you can update your applications by just sending a new script file that could even be compiled to byte code, which cannot easily be transformed back to source code. Pascal Script includes the following features: Variables, Constants Standard language constructs: Begin/End If/Then/Else For/To/Downto/Do Case x Of Repeat/Until While Uses Exit Continue Break Functions inside the script Calling any external DLL function (no special function headers required) Calling registered external methods All common types like Byte, Shortint, Char, Word, SmallInt, Cardinal, Longint, Integer, String, Real, Double, Single, Extended, Boolean, Array, Record, Enumerations, Variants Allows the importing and use of classes, with events, properties, methods and constructors Allows the importing and use of interface and their members Allows IDispatch dynamic method invocation through Variant Assignment of script functions to Delphi events Uses byte code as an intermediate format and allows storing and reloading compiled scripts Easy to use component version Support for include files Support for compiler defines Capability to call RemObjects SDK Services from within scripts Pascal Script includes a tool to create headers for importing classes and interfaces

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值