Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <conio.h>
- #define MAX 10
- int main()
- { int i, n;
- float x(MAX],y [MAX];
- float sumx=0.0, sumy=0.0, sumxx=0.0, sumxy=0.0, xmcan, ymean, denom, a, b;
- /*Reading data values*/
- printf("Input the number of data points: ");
- scanf("%d", &n);
- printf(" \n Input x and y values (one set on each line): ");
- for(i=1;i<=n;i++)
- scanf("%r/of", &x[iJ, &O]);
- /*Computing constants a and b*/
- for(i=1;i<=n;i++){
- sumx=sumx+x[i];
- sumy=sumy+y[i];
- sumxx=sumxx+x[i]*x[i];
- sumxy=sumxy+x[i]*x[i];
- }
- xmean=sumx/n;
- ymean=sumy/n;
- denom=n*sumxx-sumx*sumx;
- b=(n*sumxy-sumx*sumy)/denom;
- a=ymean-b*xmcan;
- printf(nn The line that is fit to the given data is y= %f + %fx.", a, b );
- getch 0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment