HW5.1_solutions

# HW5.1_solutions - CURGPA = NHP/NCC CUMGPA =(OHP NHP(OCC NCC...

This preview shows pages 1–2. Sign up to view the full content.

Ch. 5, Problem 2 Program mulquo Integer num1, num2, prod, quo, remain *prompt user to input values print*, 'enter two three-digit integers' read*, num1, num2 *carry out calculations to be printed to user prod = num1*num2 IF (num1 .LT. num2) THEN quo = 0 remain = 0 ELSE quo = num1 / num2 remain = num1 - quo*num2 ENDIF *print out formatted answers to user print 10, num1, quo, 'R', remain 10 format(1X,I6,I23,A3,I2) print 20, 'X', num2, '----' 20 format (1X, A1, I5, A24) print 30, '------', num2, ')', num1 30 format (1X, A6, I17, A2, I4) print '(I8)', prod END ----------------------------------------- Ch. 5, Problem 6 Program gpa Integer SNUMB CHARACTER A,B,C,D REAL OHP,OCC,OGPA,NHP,C1,G1,C2,G2,C3,G3,C4,G4,NCC,CURGPA,CUMGPA *open file containing student data and read from it OPEN (UNIT = 12, FILE = 'txt.f') READ (12,'(A5,I6,A4,F5.2,A8,F5.1)')A,SNUMB,B,OGPA,C,OCC READ (12,'(A14,8F4.1)')D,C1,G1,C2,G2,C3,G3,C4,G4 *calculation to determine current and cumulative gpa's and close file OHP = OCC * OGPA NHP = (C1*G1)+(C2*G2)+(C3*G3)+(C4*G4) NCC = C1 + C2 + C3 + C4

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CURGPA = NHP/NCC CUMGPA = (OHP + NHP)/(OCC+NCC) CLOSE(12) *print off gpa values to user print'(A13,F5.2/A16,F5.2)','CURRENT GPA =',CURGPA, + 'CUMULATIVE GPA =',CUMGPA END---------------------------------------------Chaos Problem: Program Chaos Real x0,y0,x1,x2,x3,y1,y2,y3,x,y,MP1,MP2 Integer seed,i,n x1 = 0. y1 = 0. x2 = 1. y2 = 0. x3 = 0.5 y3 = 0.866 print*,'enter x and y coordinates for the initial point and + enter how many points need to be displayed' read*, x0,y0,n OPEN (unit=24,file='chaos.txt') *random number generator generates random numbers between 0 and 1 seed=12345 do 10 i=1,n seed=seed*3 x=rand(seed) IF((x.GT.0.).AND.(x .LE. 1./3.))THEN MP1 = (x1+x0)/2. MP2 = (y1+y0)/2. x0 = MP1 y0 = MP2 write(24,*) MP1,MP2 ELSEIF ((x .GT. 1./3.).AND.(x .LE. 2./3.))THEN MP1 = (x2+x0)/2. MP2 = (y2+y0)/2. x0 = MP1 y0 = MP2 write(24,*) MP1, MP2 ELSE MP1 = (x3+x0)/2. MP2 = (y3+y0)/2. x0 = MP1 y0 = MP2 write (24,*)MP1,MP2 ENDIF 10 continue CLOSE(24) END...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

HW5.1_solutions - CURGPA = NHP/NCC CUMGPA =(OHP NHP(OCC NCC...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online