pascal竞赛辅导.doc

  1. 1、本文档共12页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
pascal竞赛辅导

请你读懂下面的这个程序,说出程序的功能 Program bijiaosangeshudaxiao (input, output) Var a, b, c, t: integer; begin write(‘input a, b, c:’); readln(a, b, c); if ab then begin t:=a; a:=b; b:=t; end; if ac then begin t:=a; a:=c; c:=t; end; if bc then begin t:=b; b:=c; c:=t; end; writeln (‘The output is:’, a, b, c) end. 输入数据10,3,21,请写出输出的结果。 作业: 给出三角形的三个边长a, b, c,求出三角形的面积。 提示:三角形的三边必须满足条件: a+bc and b+ca and c+ab 给出三边,则三角形的面积可按下面的公式计算: s=1/2(a+b+c) area(面积)=sqrt (s (s-a)(s-b)(s-c) 循环结构(for语句、while…do语句) for语句的执行过程是: 1、先将初值赋给循环变量 2、判断循环变量的值是否已超过终值,如已超过,则跳到步骤6 3、如果未超过终值,则执行“do”后面的那个语句 4、循环变量递增(或者递减)1 5、返回执行步骤2 6、循环结束,执行for循环下面的语句。 基本语句举例: for i:=1 to n do //i作为循环控制变量,当条件不满足i时即跳出循环 begin readln(a); writeln(a); end; 求n!。 提示:n!=n*(n-1)*(n-2)*(n-3)*…*1 program njiecheng ( input, output); var x: real; n, i : integer; begin write ( ‘input n , calculat n!:’); readln ( n ); if ( n0 ) then writeln (‘input n0, error!’) else begin x:=1; //定义x的初值是1 for i:=n downto 1 do //n的初值由程序开始时读入 x:=x*i; writeln(‘n!=’ , x); end end. 输入两个数x1、x2,判断它们是否是互质数 分析:(1)如果x1/x2为整数,则非互质数;(假设大数x1,小数x2) (2)如果x2和x1能同时被2-x2/2间任一整数整除,则x1和x2非互质。如36和27,能同时被3整除,故非互质(以2到27/2,作为除数,如x1和x2能被其中任一整除,则36,27非互质) program huzhishu (input, output); var x1, x2, t, n, i : integer; yes: Boolean; begin write ( ‘input x1, x2:’); readln ( x1, x2 ); if ( x1x2 ) then begin t:=x1; x1:=x2; x2:=t end; yes:=true; if ( x1 mod x2 ) = 0 then yes:=false else begin n:=x2 div 2; for i:=2 to n do if ((x1 mod i)=0) and ((x2 mod i)=0) then yes:=false end; if yes then writeln (‘They are mutual prime numbers.’) else writeln (‘They are not mutual numbers.’) end. Input x1, x2: 23 189 They are mutual prime numbers. Input x1, x2: 24 189 They are

文档评论(0)

shuwkb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档