Q / G B

advertisement
Q/GB
Suppose a movie theater has 36 seats, laid out in a rectangular six rows by
six seats. Let the seats be priced as indicated
1
1
1
1
1
1
1
2
2
2
2
1
1
2
5
5
2
1
1
2
5
5
2
1
1
2
2
2
2
1
1
1
1
1
1
1
Write a program that when given the row number and the seat number, prints
the price of a ticket. Use format statement to print your result.
program price_of_seat
implicit none
integer:: seat,row,price
read(*,*) seat,row
if(row==1.or.row==6.or.seat==1.or.seat==6)then
price=1
elseif(row==2.or.row==5.or.seat==2.or.seat==5)then
price=2
else
price=5
endif
write(*,60) price
60 format(2x,"price of the ticket=",2x,i3)
end
Q/GA
Given a quadratic equation as follows:
ܽ‫ ݔ‬ଶ ൅ ܾ‫ ݔ‬൅ ܿ ൌ Ͳ
if b*b-4*a*c is non-negative, the roots of the equation can be solved with the
following formulae:
”‘‘–ʹ ൌ
”‘‘–ͳ ൌ
ଵ
ଶୟ
൫െ„ െ ξ„ ଶ െ Ͷƒ…൯
ͳ
ቀെ„ ൅ ඥ„ ଶ െ Ͷƒ…ቁ
ʹƒ
Write a program to read in the coefficients a, b and c, and compute and display the
roots. If the discriminate b*b - 4*a*c is negative, the equation has complex root.
Thus, this program should solve the equation if the discriminate is non-negative
and show a message otherwise.
program quadratic_equation
implicit none
real:: a,b,c,d,root,root1,root2
read(*,*) a,b,c
;
d=b*b-4*a*c
if(d.gt.0)then
root1= -b/(2*a)+sqrt(d)
root2= -b/(2*a)-sqrt(d)
write(*,50) root1,root2
50 format(2x,"first root =",2x,f9.6,/,2x,"second root =",2x,f9.6)
elseif(d==0)then
root= -b/(2*a)
;
write(*,60) root
60 format (2x,"root=",2x,f9.6)
else
write(*,70) ;
endif
end
70 format (2x,"there is no solution")
Download