niemsh0007

Untitled

Apr 23rd, 2022
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <conio.h>
  4. #define MAX 10
  5. int main()
  6. { int i, n;
  7. float x(MAX],y [MAX];
  8. float sumx=0.0, sumy=0.0, sumxx=0.0, sumxy=0.0, xmcan, ymean, denom, a, b;
  9. /*Reading data values*/
  10.  printf("Input the number of data points: ");
  11. scanf("%d", &n);
  12. printf(" \n Input x and y values (one set on each line): ");
  13. for(i=1;i<=n;i++)
  14.     scanf("%r/of", &x[iJ, &O]);
  15. /*Computing constants a and b*/
  16. for(i=1;i<=n;i++){
  17. sumx=sumx+x[i];
  18. sumy=sumy+y[i];
  19. sumxx=sumxx+x[i]*x[i];
  20. sumxy=sumxy+x[i]*x[i];
  21. }
  22. xmean=sumx/n;
  23. ymean=sumy/n;
  24. denom=n*sumxx-sumx*sumx;
  25. b=(n*sumxy-sumx*sumy)/denom;
  26. a=ymean-b*xmcan;
  27. printf(nn The line that is fit to the given data is y= %f + %fx.", a, b );
  28. getch 0;
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment