/********************************************************************************* * Section 15 * M/c No : M * Roll No : 18CS100XY * Names : Soumyajit Dey, Aritra Hazra * Assignment No : 3c * Description : Program to find intervel sine function under specified resolution *********************************************************************************/ #include #include int main() { int h, i, j, k; float a, x, r; double b, y, fact_h, prev_sum, current_sum; printf("Enter resolution: "); scanf("%d", &j); printf("Enter Interval size: "); scanf("%f", &r); for(i=0; i<=j; i++) { x=2*M_PI*(float) i/ (float) j; b = sin(x); printf("sin(%0.2f pi)= %lf", 2*(float)i/(float)j, b); h=0; y=x; while(1) { h++; fact_h=1; for(k=1 ; k<= 2*h+1 ; k++) fact_h = fact_h * k; y = y + pow(-1, h) * (pow(x , (2*h+1))/ fact_h); // printf("\n interation %d -- , y = %lf\n", h, y); current_sum=y; if(fabs(current_sum - prev_sum) <= r) break; prev_sum=y; } if(current_sum <= prev_sum) printf("\t\tmy math.h gives sin(%0.2f pi)= [%lf, %lf] \n", 2*(float)i/(float)j, current_sum, prev_sum); else printf("\t\tmy math.h gives sin(%0.2f pi)= [%lf, %lf] \n", 2*(float)i/(float)j, prev_sum, current_sum); } return 0; }