Thursday, October 16, 2008

Program Of Simpsons 1/3 formulae.

void main()
{
int a[10];

cout<<:Enter the no. of terms:";
cin>>n;
cout<<"Enter the difference:";
cin>>h;

cout<<"Enter the values:";
for(i=1 ; i <= n;i++)
{
cin>>a[i];
}
if(n%2==1)
{
sum=y[1]+y[n];
for(i=2; i < =n-1;i++)
{
if(i%2==0)
sum + =4*y[i];
else
sum + =2*y[i];
}
sum = (sum*h)/3;
}

else
{
sum=y[1]+y[n-1];
for(i=2; i < = n-2; i++)
{
if(i%2==0)
sum + =4*y[i];
else
sum + =2*y[i];
}
sum=(sum*h)/3;
sum 2=((y[n-1]+y[n]) * h)/2;
sum=sum+sum2;
}

cout<<"Sum is:";
cout << sum;
getch();
}

No comments: