Date: Wed, 11 Dec 1996 22:33:39 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Thu, 19 Sep 1996 15:40:15 GMT Content-length: 2719
--------------------------------- | 0 | 1 | 1 | 0 | 0 | 0 | 1 | 1 | = 2^6 + 2^5 + 2^1 + 2^0 = 99 --------------------------------- 2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0b) REAL (4 digit mantissa, 4 digit exponent)
0110 0011 is 1.0110 x 2^0011 = [2^0 + 2^(-2) + 2^(-3)] x 2^3 = 11.0
PROGRAM SPAM IMPLICIT NONE C Number of Eggs, Sausage, Beans, Spam C Vikings, Dead Frogs, And Health Code Violations INTEFER EGGS,SAUSAG,BEANS,SPAM INTEGER VIKING,DDFROG,HEALTH EGGS = 40 SAUSAG = 200 BEANS = 100 SPAM = 20000 EDIBLE = EGGS + SAUSAG + BEANS + SPAM VIKING = 20 DDFROG = 0 HEALTH = 300 PRINT *,'Edible Food per Viking', VIKING/EDIBLE PRINT *,'(crunchy) Dead Frogs per Viking',DDFROG/VIKING PRINT *,'Health violations per dead frog',HEALTH/DDFROG STOP ENDa) Syntax Error:
INTEFER instead of INTEGER on line 6b) Semantic Error:
EDIBLE undeclaredc) Run-Time Error:
HEALTH/DDFROG is dividing by 0d) Logical Error:
Edible food per dead vikingshould be EDIBLE/VIKING (not VIKING/EDIBLE)
a)
CHARACTER*3 FUBAR FUBAR = 'CONGRESS' Only the first three characters can be stored, so FUBAR = 'CON'b)
INTEGER FUBAR FUBAR = 3.6 Integers truncate, so FUBAR = 3c)
INTEGER FUBAR FUBAR = MOD(18,5) The remainder of 18 when divied by 5 is 3.d) (Hint: Remember the conversion rules)
REAL FUBAR INTEGER X,Y FUBAR = 5/3 5 and 3 are integers, so the expression 5/3 = 1 *Then* we convert to the type of FUBAR, so FUBAR = 1.0 (Note: to avoid this, you need something like REAL(5)/3, or 5.0/3 (one operand must be real).