In: Computer Science
C Program
Write a program to read an equation
a/b*x^c*fun(alpha)+d/e*x^f*fun(beta)+g
where:
a-f are integers
alpha,beta are angles from 0,360
g is a real number(float)
fun is either sin, cos, or tangent
After reading the equation, and its parameters, ask the user to enter a range for x, and evaluate the given function.
Display a table x, fx with 10 spaces each, and 5 digits of precision.
code:
//declare stdio and math header
//for input output and power functions usage.
#include <stdio.h>
#include<math.h>
int main()
{
//declare required variables.
int a,b,c,d,e,f,alpha,beta,x;
float g;
//read user input.
printf("Enter a,b,c,d,e,f,alpha and beta values:\n");
scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&alpha,&beta);
//read x range.
printf("Enter range of x: ");
scanf("%d",&x);
//display table along with functon values.
printf("x\t|\tfx\n------------------------\n");
for(int i=0;i<x;i++)
{
printf("%d\t|\t",i);
printf("%.5f\n",(a/b*pow(i,c)*sin(alpha)+d/e*pow(i,f)*sin(beta)+g));
}
return 0;
}
-----------------------------------------------------
output:
Enter a,b,c,d,e,f,alpha and beta values:
10 5 3 8 4 3
60 90
Enter range of x: 5
x | fx
------------------------
0 | 0.00000
1 | 1.17837
2 | 9.42698
3 | 31.81605
4 | 75.41581
----------------------------
kindly comment for queries if any, upvote if you like it.
Thankyou.