In: Computer Science
Write a C program to read an equation.
a/b*x^c*fun(alpha)+d/e*x^f*fun(beta)+g
a-f are integers, alpha and beta are angle from 0-360.
g is real number(float).
function is either sin, cos or tan.
After reading the equation, and its parameters, ask the user to enter an range for x, and evaluate the given function.
Display a table x, fx with 10 spaces each, and 5 digits of precision.
Can use only pow, and the sin,cos, and tan function in math.h.
Cannot use C- strings, strings, or any other .h header.
Cannot use arrays.
The number of rows is always 11 and shows the values of x from min to max.
1. First need to include the header files required below.
# include <stdio.h>
# include <math.h>
2. Inside main declare x as integer variable,
using printf and scanf need to ask user to input the value for x i.e. range
int x;
printf("Enter an Range: ");
scanf("%d", &x);
above code is to ask range from user and storing
value into variable x.
int a, b, c , d, e, f;
float g;
ask the user to enter the values for a-f similarly as
above using printf and scanf and store them in a-f integer
variables.
now coming to equation.
we store alpha caluclation in alpha variable of type
float and beta value in beta variable of type float. For that we
declare alpha and beta variables as float.
float alph, bet ; // these are the variable which
store values of alpha and beta caluclations
we have to use For loop to evaluate function.
for For Loop declare a varible of type integer below
for loop, assuming i as variable for loop variable
int i;
also declaring
float alpha=0.0, beta=0.0;
Now assign for loop condition toi <=11 and increment i by 1, below is for loop example
for(i =1;i<=11;i++)
{
// now caluclating alpha,similarly
beta part.
alph = a/b*pow(x,
c)*fun(alpha);
bet = d/e*pow(x,
f)*fun(beta);
alpha = alpha+32.73;
beta = beta+32.73
// using another for loop with
variable j for cells in a table
for(j=1;j<=2;j++)
{
printf("%d", x);
printf("\t"); //
\t prints three spaces nothing but tab.
printf("\t");
printf("\t");
printf(" ");
//after calucation of alpha and beta values, we
will add that with g
printf("%0.5f ", alph+bet+g);
printf("\n"); // printing new line after
printing fx and x values.
}
}
// I have no idea what fun is doing , as it is not mentioned i am skipping that part and let me know if you have more information regarding that.
Please send your queries or request if you need help.