Homework #09 |
Due: April 7, 2025 |
#include <stdio.h> int main() { double x, y, z; int i,n; x=y=z=0.0; printf("Enter # of iteration = "); scanf("%d", &n); for (i=0;i<n;i++) { x = (10-y-2*z)/7; y = (8-x-3*z)/8.0; z = (6-2*x-3*y)/9.0; } printf("x = %lf, y= %lf, z=%lf\n", x,y,z); return 0; } |
fprintf('x = %f, y= %f, z=%f\n', x,y,z); |
/* Simpson's rule */ #include <stdio.h> #include <math.h> double f(double x) {return 4.0/(1.0+x*x);} int main() { int i, n ; double a=0.0, b=1.0 , h, s1=0.0, s2=0.0, s3=0.0, x; printf("Enter number of partitions (must be even) = "); scanf("%d", &n) ; h = (b-a)/(2.0*n) ; s1 = (f(a)+ f(b)); for (i=1; i<2*n; i=i+2) s2 = s2 + f(a + i*h); for (i=2; i<2*n; i=i+2) s3 = s3 + f(a + i*h); printf("%20.12lf\n", (h/3.0)*(s1+ 4.0*s2 + 2.0*s3)) ; return 0; } |