Must be written in c and also you pthreads Must be written i
Must be written in \'c\' and also you pthreads
Must be written in \'C\' For this lab you will write a pthreads program that will calculate the integral of sqrt(4 - x*x) from 0 to 2 using the trapezoidal rule. There will be no more than 50 partitions. The user will input the number of partitions they want to use.
Remember to include math.h in the code and do the -lm in the compile line.
Solution
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
float f(float);
void main()
{float a,b,h,sum,x,trap;
int n,i,m;
cout<<\"Enter the limits a & b & number of subintervals n\ \";
cin>>a>>b>>n;
h=(b-a)/n;
sum=0.0;
m=n-1;
for(i=1;i<=m;i++)
{x=a+i*h;
sum=sum+f(x);
}
trap=h*(f(a)+2.0*sum+f(b))/2.0;
cout<<\"Value of integral with \"<<n<<endl;
cout<<\"Subintervals=\"<<trap;
getche();
}
float f(float x)
{float fun;
fun=1.0/(1+x);
return(fun);
}
