The maximum zero mass is the maximum
Classified in Computers
Written at on English with a size of 1.97 KB.
Tweet |
a) Write function to evaluate the mathematical function: f(x) = sin(2*x)*exp(-x) in a given point.
b) Write a C program to evaluate the previous function in a given set of data by specifying 3 data: a min-value, a max-value and the step h. The output should be presented like the following example:
f(x) is evaluated from -2 to 2 with a step of 0.2
nº x f(x)
1 -2 *
2 -1.8 *
3 -1.6 *
#include<stdio.H>
#include<math.H>
float f_x(float);
float f_x(float x)
{float y;
y=sin(2*x)*exp(-x);
return(y);}
int main()
{float x,h,l1,l2;
printf("introduce lower limit \n");
scanf("%f",&l1);
printf("introduce upper limit \n");
scanf("%f",&l2);
printf("introduce the step \n");
scanf("%f",&h);
printf("x f(x) \n");
for(x=l1;x<=l2;x=x+h)
printf("%g %g \n", x,f_x(x));}
Maximum, Minimum and Average of two numbers
#include<stdio.H>
float max(float, float);
float min(float, float);
float ave(float, float);
float max(float x, float y)
{if (x>y)
return(x);
else
return(y);}
float min(float x, float y)
{if (x<y)
return(x);
else
return(y);}
float ave(float x, float y)
{return((x+y)/2);}
int main(){float x=3.0,y=4.0;
printf("the maximun value is %f \n", max(x,y));
printf("the minimum value is %f \n", min(x,y));
printf("the average value is %f \n", ave(x,y));}