# Coding for the mathematical function in C

#### Vishaka

I have a function
f(t) = e^(−5) e^(−5cos cos(t)) e^(10cos(t)) e^(−5sin sin(t))
I need to find the value of f for different values of t. Let us say from t=0 to t=5. How to write coding for that?. I just know some basics of C

#### CodeMonkeyJ

Below should get you started. The formula was a bit hard to read, so I kind of guessed. I split the different factors up to make it a little easier to read. You have to include to the math library to compile it, e.g., `gcc -lm formula.c`.

C:
``````#include <stdio.h>
#include <math.h>

const double e = 2.7182818284590452353602874713527;

double f(double t){
const double f1 = pow(e, -5);
const double f2 = pow(e, -5 * cos(cos(t)));
const double f3 = pow(e, 10 * cos(t));
const double f4 = pow(e, -5 * sin(sin(t)));
return f1 * f2 * f3 * f4;
}

int main(){
printf("f(%f) = %f\n", 0., f(0.));
printf("f(%f) = %f\n", 1., f(1.));
printf("f(%f) = %f\n", 2., f(2.));
printf("f(%f) = %f\n", 3., f(3.));
printf("f(%f) = %f\n", 4., f(4.));
return 0;
}``````
If you've got any questions or want anything explained, let me know.