Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 1 (60 marks) Write a Fortran program that reads a number from the keyboard

ID: 441428 • Letter: P

Question

Part 1 (60 marks) Write a Fortran program that reads a number from the keyboard and then outputs a message indicating whether or not the number is abundant. If the input is 24, the output should be: The number 24 is abundant If the input is 29, the output should be: The number 29 is not abundant Part 2 (40 marks) The smallest abundant number that is odd (not divisible by 2) is 945. Write a Fortran program that prints the value of the all odd abundant numbers less than 5000. Your program must include a loop that checks each number less than 5000 to determine whether or not it is abundant and also odd. The program for part 2 must have a loop that checks a sequence of numbers. That is you must not just hardcode the solution

Explanation / Answer

follow this FORMAT DESCRIPTORS - The elements in the I/O list must agree in TYPE with the FORMAT DESCRIPTOR being used. - There are a dozen or so descriptors, The most commonly used are: Descriptor Use rIw Integer data rFw.d Real data in decimal notation rEw.d Real data in scientific notation Aw Character data 'x...x' Character strings nX Horizontal spacing (skip spaces) / Vertical spacing (skip lines) Tc Tab Where: w = positive integer specifying FIELD WIDTH r = positive integer REPEAT COUNT d = non-negative integer specifying number of digits to display to right of decimal. x = any character n = positive integer specifying number of columns c = positive integer representing column number NOTES ON DESCRIPTORS: - Values for I, F, and E descriptors will be right justified. - You must leave enough space for negative sign in the field width for I, E, F, and for decimal point for E, F and for exponent for E. - When using the E descriptor, the number will be NORMALIZED. This means the number is shifted over so that the first digit is in the tenths position. A leading zero and decimal are always present and a minus sign, if needed. The exponent always requires 4 spaces; E, the sign and 2 digits. - If you overflow the space allotted to a descriptor, it will print out asterisks (at RUN TIME) in the field space. - Character data (A) is also right-justified but if it overflows the allotted space it is left-most truncated. - The first character of each line of output is used to control the vertical spacing. Use 1X to give normal spacing. MORE COMPLICATED EXAMPLES: 1. Format identifier Given: REAL ROOT1, ROOT2 1. Unformatted or "free format" output: All three are equivalent Print*, root1, root2 Write (6,*) root1, root2 Write (6,*) 'Roots are:' root1, root2 2. Formatted write statements: Write (6,100) root1, root2 100 format (1x, 'The Roots Are: ', F5.1,1x,F5.1) output: The Roots Are: 123.5 789.1 3. Write(6,'(',The Roots Are: ', 2F5.1)') root1,root2   4. Define character*5 FRMT FRMT = '2F5.1' write(6,FRMT) root1, root2 2. Format Descriptors Integer: Iw examples: NUM1 = 123, NUM2 = 456, NUM3 =9 write(6,15) NUM1, NUM2, NUM3 15 format (1x,I3,1x,I3,1x,I3) output: 123 456 9 ^ ^ ^^^ write(6,18) NUM1, NUM2, NUM3 18 format (1x,3(I2,1x)) output: *** *** *** Note: If the number is too large ^ ^ ^^ for #spaces allotted, *** are printed. Reals: REAL NUMBER1, NUMBER2 NUMBER1 = -123.5678 NUMBER2 = -23456.89 A. F format (decimal) Fw.d d=# places to right of decimal w-d > or = 2 (to include the decimal pt and +/- sign) NUMBER1 needs format F9.4 NUMBER2 needs format F9.2 B. E format -- good for 1) large or small numbers 2) don't know the size of number Ew.d w - d > or = 7: need at least 7 places for: e-03 -- 4 places +/- -- 1 place 0. -- 2 places NUMBER1 needs format E14.7 -0.1235678E+03 NUMBER2 need foprmat E14.7 -0.2345689E+05 C. G-format G10,3 chooses between E & F format depending on the size of the number D. D-format Dw.d same as E, but for Double Precision D10.3 1.473D-05 Character Variables: CHARACTER*10 NAME REAL SCORE1, SCORE2 A-format Aw w = # characters read(10,100) NAME, SCORE1, SCORE2 100 format(A10,1x,f6.1,1x,f6.2) read this one line from input file, unit=10 JORDAN____ __98.4 __75.5 write(20,150) NAME 150 format(1x,'Last name = ', A10) output file (unit=20) line is: Last name = JORDAN____ writes out left justified If we write NAME in A5 format Last name = JORDA truncated: not enough characters * When reading in "free format" for a character string, your input needs single quotes around it. read*, name keyboard input: 'JORDAN' * When reading a character string using a format statement, you do not need the single quotes. read(*,50) name 50 format(A10) keyboard input: JORDAN no quotes!! 3. Control of Horizontal Spacing. 1. nX skips n spaces read (10,150) INTEGER1, INTEGER2 150 format (I3, 12x, I3) skips everything in between 2. Tabs! Tc c = column number Great for tables!! format (1x, F7.2, T12, F7.1, T24, I6)  starts in Column 12 4. File Types: Sequential: lines of data or records are written in a sequence and must be read in that (Chapter 11) sequence. If you want to ignore 4 lines and then read 5th line . . . Must READ all 4 lines first, then start with 5th line. NO WAY TO SKIP to 5th line. Direct-access files: Records have specified Record Length (RECL). Each record can be accessed individually You can skip to the 5th record. 5. Open Statements p.518 Open (unit=10, file='mydata', status='old') status = old, new, unknown You can use a character variable name, for example: character*30 file1 file1= '/home/usr6/mr2020/lab4.data' open (unit=10, file=file1, status='old', readonly) The readonly option will not allow you to write to unit=10. This protects your file from accidentally being overwritten. To write to files: open(unit=20,file='Lab4.output',status='new') If status='new' and then you rerun the program, the file Lab4.output already exists from the last time you ran the program, so the program stops!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote