Advertisement
cd62131

Statistics

Jul 23rd, 2014
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(void) {
  3.   int i, n;
  4.   double x[BUFSIZ], y[BUFSIZ], sumx, sumy, sumxx, sumxy, aa, a0, a1;
  5.   sumx = sumy = sumxx = sumxy =0.;
  6.   printf("n = ");
  7.   scanf("%d", &n);
  8.  
  9.   printf("input x y:\n");
  10.   for (i = 0; i < n; i++) {
  11.     printf("%d ? ", i);
  12.     scanf("%lf%lf", &x[i], &y[i]);
  13.   }
  14.  
  15.   for (i = 0; i < n; i++)
  16.     sumx += x[i];
  17.  
  18.   for (i = 0; i < n; i++)
  19.     sumy += y[i];
  20.  
  21.   for (i = 0; i < n; i++)
  22.     sumxx += x[i] * x[i];
  23.  
  24.   for (i = 0; i < n; i++)
  25.     sumxy += x[i] * y[i];
  26.  
  27.   aa = n * sumxx - sumx * sumx;
  28.   a0 = (sumxx * sumy - sumx * sumxy) / aa;
  29.   a1 = (n * sumxy - sumx * sumy) / aa;
  30.   printf("a0 = %g\n", a0);
  31.   printf("a1 = %g\n", a1);
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement