- #1
Const@ntine
- 285
- 18
The statement:
In every ABC triangle, the laws of sine (a/sinA = b/sinB = c/sinC) & cosine (c2 = a2 + b2 -2*a*b*cosC) are valid, where a, b & c are the sides opposite to A, B & C respectively.
Write a program that calculates and prints on the computer's screen, the length of c, and also the unit of the angles A & B of an ABC triangle. The lengths of a & b, plus the unit of C (in radians) shall be given by the keyboard.
The attempt at a solution
Here's what I have so far:
PROGRAM
REAL :: a, b, c,angle_in_degree_A, angle_in_degree_B, angle_in_degree_C, angle_in_radian_A, angle_in_radian_B, angle_in_radian_C
REAL :: pi = 3.14159265
PRINT*, 'ENTER THE FIRST SIDE OF THE TRIANGLE'
READ*, a
PRINT*, 'FIRST SIDE (a) = ', a
PRINT*, 'ENTER THE SECOND SIDE OF THE TRIANGLE'
READ*, b
PRINT*, 'SECOND SIDE (b) = ', b
PRINT*, 'ENTER THE ANGLE BETWEEN THE TWO SIDES'
READ*, angle_in_degree_C
PRINT*, 'ANGLE IN DEGREE C = ', angle_in_degree_C
angle_in_radian_C = (angle_in_degree_C*pi)/180.0
PRINT*, 'ANGLE IN RADIAN C = ', angle_in_radian_C
c = SQRT (a**2 + b**2 - 2.*a*b*COS(angle_in_radian_C))
PRINT*, 'THIRD SIDE OF TRIANGLE =', c
angle_in_degree_A = (angle_in_radian_A)*180.0/pi
angle_in_radian_A = ASIN(SIN(angle_in_radian_C)*a/c)
PRINT*, 'ANGLE IN DEGREE A = ',angle_in_degree_A
END
We were given this assignment on Wednesday for our programming class, and it's due tomorrow. Problem is, the system here is a bit, well, weird, and I know little to nothing about Fortran. I was studying C++ (yes, two languages in one semester that starts in Novemeber and ends in January, amongst the other 6 subjects with a 600pg+ syllabus-and everything is mandatory), so I could really use the help.
I managed to take a look at the book and with the internet's help, I came up with a way to find the third side of the triangle. My problem now is that I can't find the angles. I checked and saw that the arcsin command is ASIN, but when I put it in my editor, the words become red, and while it compiles, I don't get the desired result.
I could really use some help here. But I warn you, I don't know anything beyond the basic commands, so simplify it as much as you can. I wasn't even planning on taking the subject, but here, things work differently. You get into a department of the University, and you attend mandatory classes that have been assigned to you by the department itself, you can't choose. So, as someone who never "played around" with programming before, it's a bit of hurdle for me to learn Fortran & C++ in ~4 months, amongst the other 6 subjects that go with the Physics Department acceptance.
Any kind of help is appreciated.
In every ABC triangle, the laws of sine (a/sinA = b/sinB = c/sinC) & cosine (c2 = a2 + b2 -2*a*b*cosC) are valid, where a, b & c are the sides opposite to A, B & C respectively.
Write a program that calculates and prints on the computer's screen, the length of c, and also the unit of the angles A & B of an ABC triangle. The lengths of a & b, plus the unit of C (in radians) shall be given by the keyboard.
The attempt at a solution
Here's what I have so far:
PROGRAM
REAL :: a, b, c,angle_in_degree_A, angle_in_degree_B, angle_in_degree_C, angle_in_radian_A, angle_in_radian_B, angle_in_radian_C
REAL :: pi = 3.14159265
PRINT*, 'ENTER THE FIRST SIDE OF THE TRIANGLE'
READ*, a
PRINT*, 'FIRST SIDE (a) = ', a
PRINT*, 'ENTER THE SECOND SIDE OF THE TRIANGLE'
READ*, b
PRINT*, 'SECOND SIDE (b) = ', b
PRINT*, 'ENTER THE ANGLE BETWEEN THE TWO SIDES'
READ*, angle_in_degree_C
PRINT*, 'ANGLE IN DEGREE C = ', angle_in_degree_C
angle_in_radian_C = (angle_in_degree_C*pi)/180.0
PRINT*, 'ANGLE IN RADIAN C = ', angle_in_radian_C
c = SQRT (a**2 + b**2 - 2.*a*b*COS(angle_in_radian_C))
PRINT*, 'THIRD SIDE OF TRIANGLE =', c
angle_in_degree_A = (angle_in_radian_A)*180.0/pi
angle_in_radian_A = ASIN(SIN(angle_in_radian_C)*a/c)
PRINT*, 'ANGLE IN DEGREE A = ',angle_in_degree_A
END
We were given this assignment on Wednesday for our programming class, and it's due tomorrow. Problem is, the system here is a bit, well, weird, and I know little to nothing about Fortran. I was studying C++ (yes, two languages in one semester that starts in Novemeber and ends in January, amongst the other 6 subjects with a 600pg+ syllabus-and everything is mandatory), so I could really use the help.
I managed to take a look at the book and with the internet's help, I came up with a way to find the third side of the triangle. My problem now is that I can't find the angles. I checked and saw that the arcsin command is ASIN, but when I put it in my editor, the words become red, and while it compiles, I don't get the desired result.
I could really use some help here. But I warn you, I don't know anything beyond the basic commands, so simplify it as much as you can. I wasn't even planning on taking the subject, but here, things work differently. You get into a department of the University, and you attend mandatory classes that have been assigned to you by the department itself, you can't choose. So, as someone who never "played around" with programming before, it's a bit of hurdle for me to learn Fortran & C++ in ~4 months, amongst the other 6 subjects that go with the Physics Department acceptance.
Any kind of help is appreciated.