Write a Fortran program called trigtable.f95 that creates (prints to the console
ID: 3586118 • Letter: W
Question
Write a Fortran program called trigtable.f95 that creates (prints to the console) a nice table of the values of sine, cosine, tangent, secant, cosecant, and cotangent at all even degree multiples of 10º and 15º between 0º and 360º. (The mod function may be useful here.) You may do this using arrays or without, depending on your preference.
The table should have a header row and a separator row. The angle should be shown as an integer in a width 4 field and each trigonometric value in the table should have width 8 with 4 digits to the right of the decimal place. Some functions will give infinite results for certain angles, so check and print INF for those results.
Explanation / Answer
Answer:
import java.util *;
class Trigo
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int degree=sc.nextInt();
double radians = Math.toRadians(degree);
double sine = Math.sin(radians);
double cos = Math.cos(radians);
double tan = Math.tan(radians);
double sec = (1 / sine);
double cosec = (1 / cos);
double cot = (1 / tan);
System.out.println("sin("+degree+") = "+sine);
System.out.println(" ");
System.out.println("cos("+degree+") = "+cos);
System.out.println(" ");
System.out.println("tan("+degree+") = "+tan;
System.out.println(" ");
System.out.println("-------------");
System.out.println("sec("+degree+") = "+sec);
System.out.println(" ");
System.out.println("cosec("+degree+") = "+cosec);
System.out.println(" ");
System.out.println("cot("+degree+") = "+cot);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.