Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void) {
- int i, n;
- double x[BUFSIZ], y[BUFSIZ], sumx, sumy, sumxx, sumxy, aa, a0, a1;
- sumx = sumy = sumxx = sumxy =0.;
- printf("n = ");
- scanf("%d", &n);
- printf("input x y:\n");
- for (i = 0; i < n; i++) {
- printf("%d ? ", i);
- scanf("%lf%lf", &x[i], &y[i]);
- }
- for (i = 0; i < n; i++)
- sumx += x[i];
- for (i = 0; i < n; i++)
- sumy += y[i];
- for (i = 0; i < n; i++)
- sumxx += x[i] * x[i];
- for (i = 0; i < n; i++)
- sumxy += x[i] * y[i];
- aa = n * sumxx - sumx * sumx;
- a0 = (sumxx * sumy - sumx * sumxy) / aa;
- a1 = (n * sumxy - sumx * sumy) / aa;
- printf("a0 = %g\n", a0);
- printf("a1 = %g\n", a1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement