Write a fortran program that creates (prints to the console) a nice table of the
ID: 3586082 • Letter: W
Question
Write a fortran program 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
This program will create table according to you mantioned.
compile this c program with -lm if you are using gcc compiler.
#include <stdio.h>
#include <math.h>
#define PI 3.14159265
#define SINE 0
#define COSINE 1
#define TANGENT 2
#define COSEC 3
#define SEC 4
#define COT 5
int main ()
{
double ret=0, val=0;
int i =0 , x =0;
float treg[6]= {0.0,0.0,0.0,0.0,0.0,0.0};
val = PI / 180;
for(i=0 ;i<60 ;i++)
printf("-");
printf(" ");
printf("| TREGONOMETRIC TABLE | ");
for(i=0 ;i<60 ;i++)
printf("-");
printf(" ");
printf("| | sine | cosine | tangent| secant |cosecant| cot | ");
for(i=0 ;i<60 ;i++)
printf("-");
printf(" ");
for(x=0;x<=360;x++)
{
if(((float)(x%10) == (float) 0 ) || ((float)(x%15) == (float) 0 ))
{
treg[SINE] = sin(x*val);
treg[COSINE] = cos(x*val);
treg[TANGENT] = tan(x*val);
treg[COSEC] = 1/treg[SINE];
treg[SEC] = 1/treg[COSINE];
treg[COT]= 1/treg[TANGENT];
if(x == 90 || x == 270 )
printf("|%4d|%8.4f|%8.4f|%8s|%8s|%8.4f|%8.4f| ",x,treg[SINE],treg[COSINE],"inf","inf",treg[COSEC],treg[COT]);
else if (x == 180 || x == 360 )
printf("|%4d|%8.4f|%8.4f|%8.4f|%8.4f|%8s|%8s| ",x,treg[SINE],treg[COSINE],treg[TANGENT],treg[SEC],"inf","inf");
else
printf("|%4d|%8.4f|%8.4f|%8.4f|%8.4f|%8.4f|%8.4f| ",x,treg[SINE],treg[COSINE],treg[TANGENT],treg[SEC],treg[COSEC],treg[COT]);
for(i=0 ;i<60 ;i++)
printf("-");
printf(" ");
}
}
return(0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.