Develop a Ccode to meet the requirements below Plot fx versu
Develop a C-code to meet the requirements below: Plot f(x) versus x on a graph using any plot programs (Excel) Fit polynomials to the data using second-order polynomial Regression y = (a0 + a1 + a2x^2) Use Simpson\'s Rule to calculate integral f(x) dx, where a_0, a_1, and a_2 Are determined in step 1). The integration is limited between x values (0.5 - 7.5) Requirements:- Use C-code must contain the following features:- User of arrays, Use Of pointers Use of structure, Use of union, Use of functions and Function calls, Formatted output on screen and Saving of the same Output on a file.
Solution
Solution:
#include<stdio.h>
void main()
{
int *x, *y, n, i, x1=0, x12=0, y1=0, x1y1=0, a1, a0, e;
printf(\"Enter how many values:\");
scanf(\"%d\", &n);
x=(float*)malloc(n*4);
y=(float*)malloc(n*4);
puts(\"Enter correspnding elements X and Y\");
for(i=0; i<n;i++)
{
scanf(\"%d %d\", &x[i], &y[i]);
x1+=x[i];
y1+=y[i];
x1y1+=(x[i]*y[i]);
x12+=(x[i]*x[i]);
}
a1 = (n*x1y1-x1*y1)/(n*x12-x1*x1);
a0=y1/n-a1*x1/n;
e=y[0]-a0-a1*x[0];
printf(\"a0= %d \ a1 = %d \ e= %d\", a0, a1, e);
}
