{"id":50,"date":"2017-09-11T13:10:40","date_gmt":"2017-09-11T16:10:40","guid":{"rendered":"http:\/\/www.professores.uff.br\/diomarcesarlobao\/?page_id=50"},"modified":"2017-09-11T13:10:40","modified_gmt":"2017-09-11T16:10:40","slug":"arithp-f","status":"publish","type":"page","link":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/arithp-f\/","title":{"rendered":"arithp.f"},"content":{"rendered":"<pre>c &lt;html&gt;\r\nc &lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt;\r\nc &lt;body&gt;\r\nc &lt;pre&gt;\r\nc\r\n      program arith\r\nc\r\nc       John Mahaffy,  Penn State University, CmpSc 201 Example\r\nc       1\/26\/96\r\nc\r\nc\r\nc   Program to demonstrate Arithmetic Assignments\r\nc\r\n      implicit none\r\nc\r\nc     declare the data types for all Fortran variables\r\nc\r\n      real r2,r3,r4,r5,r6,ans1,ans2,ans3\r\n      integer i2,i3,i4,i5,i6,ians1,ians2,ians3,ians4\r\nc\r\nc     r2 thru r6 take on the real values 2.0 thru 6.0\r\nc\r\nc     i2 thru i6 take on the integer values 2 thru 6\r\nc\r\nc     ans1, ans2, and ans3 will contain the answers from\r\nc     real arithmetic\r\nc\r\nc     ians1 thru ians4 will contain the answers from\r\nc     integer arithmetic\r\nc\r\nc\r\nc     Set initial values of the variables with\r\nc     parameter statements\r\nc &lt;a name=\"para\"&gt;&lt;font color=\"FF0000\"&gt;\r\n      parameter (r2=2.0,r3=3.0,r4=4.0,r5=5.0)\r\nc &lt;\/font&gt;&lt;\/a&gt;\r\nc\r\nc     parameter statements let you do arithmetic in setting values\r\nc     The arithmetic can include the use of previously set parameters\r\nc\r\n      parameter (i2=2,i3=i2+1,i4=2*i2,i5=i2+i3)\r\nc\r\nc     This ends the non-executable statements, nothing above\r\nc     this point results in a machine instruction to perform\r\nc     some operation.\r\nc\r\nc     Executable statements follow.\r\nc\r\nc\r\nc     The result of any integer divide is truncated to the integer\r\nc     value less than the correct decimal answer for the division\r\nc     The result of this is that changing the order of operations\r\nc     can make a big difference in the answers.  Notice how parentheses\r\nc     force more expected results\r\nc\r\n      ians1=i2*i3\/i5\r\n      ians2=i3\/i5*i2\r\n      ians3=i2*(i3\/i5)\r\n      ians4=(i3\/i5)*i2\r\n      print *, '2*3\/5 =', ians1, ', 3\/5*2 =',ians2,\r\n     &amp;  ', 2*(3\/5) =',ians3 ,', (3\/5)*2 =',ians4\r\nc\r\nc    To understand one restriction on parameters, remove the \"c\" from\r\nc    the following line resetting r2.  The program won't compile\r\nc      r2= 20.0\r\nc\r\nc     Real arithmetic behaves more uniformly\r\nc\r\n      ans1=r2*r3\/r5\r\n      ans2=r3\/r5*r2\r\n      ans3=(r3\/r5)*r2\r\n      print *, '2.0*3.0\/5.0 =', ans1, ', 3.0\/5.0*2.0 =',ans2,\r\n     &amp;  ', (3.0\/5.0)*2.0 =',ans3\r\nc\r\nc     Watch how precedence of operations effects the following:\r\nc\r\n      ians1=i2+i5*i3**i2\r\n      ians2=i5*i3**i2+i2\r\n      ians3=i3**i2*i5+i2\r\n      print *, '2+5*3**2 =',ians1,', 5*3**2+2 =',ians2,\r\n     &amp; ', 3**2*5+2 =',ians3\r\nc\r\nc     You can mix real and integers, but watch what happens\r\nc\r\nc\r\n      ans1=r5+i3\/i2\r\n      print *, '5.0+3\/2 =',ans1\r\n\r\nc\r\nc     You can do the same thing with constants in the expression\r\nc\r\n      ans2=5.0+3\/2\r\n      print *, '5.0+3\/2 =',ans2\r\nc\r\nc     Look at what happens when I put a real in either the numerator\r\nc     or denominator of the division term\r\n      ans1=r5+i3\/r2\r\n      ans2=r5+r3\/i2\r\n      print *, '5.0+3\/2.0 =',ans1, ', 5.0+3.0\/2 =', ans2\r\nc\r\nc\r\nc     Although Fortran normally works from left to right at a given\r\nc     level of precedence (does all multiply and divide from left to\r\nc     right before moving on to adds and subtracts).  It works\r\nc     exponentiation from right to left when it hits 2 or more\r\nc     sequential exponentiation operations\r\nc\r\n      ians1= i5**i3**i2\r\n      ians2= (i5**i3)**i2\r\n      ians3= i5**(i3**i2)\r\n      print *, '5**3**2 =',ians1, ', (5**3)**2 =',ians2,\r\n     &amp;  ', 5**(3**2) =',ians3\r\nc\r\nc    When in doubt use parentheses to get the answer that you\r\nc    really want.\r\nc\r\n      stop\r\n      end\r\nc &lt;\/pre&gt;\r\nc &lt;\/body&gt;\r\nc &lt;\/html&gt;\r\nc<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>c &lt;html&gt; c &lt;head&gt;&lt;title&gt;&lt;\/title&gt;&lt;\/head&gt; c &lt;body&gt; c &lt;pre&gt; c program arith c c John Mahaffy, Penn State University, CmpSc 201 Example c 1\/26\/96 c c c Program to demonstrate Arithmetic Assignments c implicit none c c declare the data types for all Fortran variables c real r2,r3,r4,r5,r6,ans1,ans2,ans3 integer i2,i3,i4,i5,i6,ians1,ians2,ians3,ians4 c c r2 thru r6 take [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[],"tags":[],"class_list":["post-50","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/50","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/comments?post=50"}],"version-history":[{"count":1,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/50\/revisions"}],"predecessor-version":[{"id":51,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/pages\/50\/revisions\/51"}],"wp:attachment":[{"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/media?parent=50"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/categories?post=50"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.professores.uff.br\/diomarcesarlobao\/wp-json\/wp\/v2\/tags?post=50"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}