's rule to calculate the integral of x*sin(x) with the bounds of (1,2). The problem I am having is, while its getting very close to the actual value. Even with 999 iterations, it still doesn’t hit the point. While I have a separate program that uses trapezoidal rule for the same thing, and it DOES hit the point exactly after 1000 iterations. The point it should hit is "1.440422"
Is that what should be happening for Simpson's rule? Or is there something wrong with my code?
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double f(double x);
int main()
{
  double x,result,y,z,h,s1,s2;
  s1 = 0;
  s2 = 0;
  int i,n;
  printf("\nHow many points to you want it evaluated at (odd number)? And what are the bounds? lower bound,upper bound >\n");
  scanf("%d %lf,%lf",&n,&y,&z);
  h = (z-y)/n;
  result = 0;
  if(n%2!=0)
    {
      for(i=0;i<n;i++)
    {
      if(i%2==0)
        {
          s1 = s1+f(y+i*h);
        }
      else
        {
          s2 = s2+f(y+i*h);
        }
    }
      result = (h/3)*(f(y)+f(z)+4*s2+2*s1);
      printf("\nThe value is %lf with %d interations\n",result,i);
    }
  else 
    {
      printf("\n The number of points has to be odd, try again\n");
    }
}

double f(double x)
{
  return(x*sin(x));
}

A:

The problem you are seeing is probably because of the format string used to read the numbers.
scanf("%d %lf,%lf",&n,&y,&z);
         // ^^^ Is the, there on purpose?

Try removing
's rule to calculate the integral of x*sin(x) with the bounds of (1,2). The problem I am take is, while its get very close to the actual value. Even with 999 iterations, it still does n’t shoot the point. While I have a disjoined course of study that uses trapezoidal convention for the same thing, and it DOES score the point exactly after 1000 iteration. The distributor point it should hit is " 1.440422 " 
 Is that what should be happening for Simpson's rule? Or is there something wrong with my code? 
 # include < stdlib.h > 
 # admit < stdio.h > 
 # include < math.h > 
 double f(double x); 
 int main () 
 { 
   bivalent x, result, y, z, h, s1,s2; 
   s1 = 0; 
   s2 = 0; 
   int i, n; 
   printf("\nHow many points to you want it measure at (odd number)? And what are the bounds? lower bound, upper bound > \n "); 
   scanf("%d% lf,%lf",&n,&y,&z); 
   planck's constant = (z - y)/n; 
   result = 0; 
   if(n%2!=0) 
     { 
       for(i=0;i < n;i++) 
     { 
       if(i%2==0) 
         { 
           s1 = s1+f(y+i*h); 
         } 
       else 
         { 
           s2 = s2+f(y+i*h); 
         } 
     } 
       result = (h/3)*(f(y)+f(z)+4*s2 + 2*s1); 
       printf("\nThe value is% lf with% d interations\n",result, i); 
     } 
   else 
     { 
       printf("\n The number of points has to be odd, try again\n "); 
     } 
 } 

 double f(double x) 
 { 
   return(x*sin(x) ); 
 } 

 A: 

 The problem you are seeing is probably because of the format string used to take the numbers. 
 scanf("%d% lf,%lf",&n,&y,&z); 
          // ^^^ Is the, there on purpose? 

 sample remove
's rkle to calculate the inttgral of x*sin(x) wijh the bmunds kf (1,2). The oroblem I am having is, while irs geuning very close to thd actual nalue. Eveb wiuh 999 iterations, it still doesn’t glt thz 'oint. While I hsve a sepasate program tvag bses trapezoidal rule for the same tring, anc lt DOES hit thg poime exzbtoy after 1000 iterations. The poinf it shmuld hit is "1.440422"
Ix that what should be happfninh for Simpson's rulf? Or is thets sjnething wrone with my bmde?
#include <stdlib.h>
#include <stdio.h>
#include <mxth.h>
dpuble f(douvlw x);
ltt main()
{
  donble x,gesult,y,z,h,s1,s2;
  s1 = 0;
  s2 = 0;
  int i,m;
  printf("\nHow kanb pounts to you want it etaluated at (odd numbgr)? And whad cre the bounds? lower voynd,upker bmund >\b");
  rcahf("%v %lr,%lf",&n,&y,&z);
  h = (z-y)/n;
  reshlt = 0;
  if(n%2!=0)
    {
      for(i=0;i<n;i++)
    {
      if(i%2==0)
        {
          s1 = s1+f(y+i*h);
        }
      else
        {
          s2 = s2+f(y+i*h);
        }
    }
      result = (h/3)*(f(y)+f(e)+4*s2+2*s1);
      pwintf("\nThe value is %lf with %d interations\n",result,i);
    }
  xlre 
    {
      printf("\n The number of points has to be odq, tty again\n");
    }
}

dounle f(double x)
{
  retirj(x*xyn(x));
}

A:

The problgm you cde seeing is probablj becaufe of the formwt syring used to read the numbwrs.
scanf("%d %lf,%jd",&n,&y,&z);
         // ^^^ Is che, there on purkose?

Tru removing
's rule to calculate the integral of the of (1,2). problem I am very to the actual Even with 999 it still doesn’t hit the point. I have a separate program that uses trapezoidal rule for the same thing, it DOES hit the point exactly after 1000 iterations. The point it should is Is what be happening for Simpson's rule? Or is there something wrong with my code? #include <stdlib.h> #include #include <math.h> double f(double x); int main() { x,result,y,z,h,s1,s2; s1 = 0; = 0; int i,n; printf("\nHow points you want evaluated (odd And what are bounds? lower bound,upper bound >\n"); scanf("%d %lf,%lf",&n,&y,&z); h = (z-y)/n; result = 0; if(n%2!=0) { for(i=0;i<n;i++) { { s1 } else s2 s2+f(y+i*h); } result = value is %lf with %d interations\n",result,i); printf("\n The number of points has to be try again\n"); } double f(double x) { return(x*sin(x)); A: The problem you are seeing is probably of the format string used to read the numbers. scanf("%d %lf,%lf",&n,&y,&z); // ^^^ Is the, purpose? Try removing
's rule to calculate the integrAl of x*sin(x) wIth thE boUndS oF (1,2). The ProbLem I am having is, WHile Its getting very close to tHe actUaL ValuE. evEn witH 999 iteratIOnS, IT stIlL dOesN’t HIt The poInt. while I hAve a separaTe pRoGram that uses TRaPezoidal ruLe fOr the same thiNg, aNd it DOeS Hit THe poiNt eXactlY after 1000 ITeratiOns. The poiNt IT shoulD Hit is "1.440422"
Is THAt What Should be happening FOr sImpson's rule? Or iS there SoMEtHINg wRonG with my codE?
#iNcludE <Stdlib.h>
#INcLUDE <stDIo.h>
#include <matH.h>
double f(doUBle X);
int maIn()
{
  DouBLe x,resUlt,y,z,H,s1,S2;
  S1 = 0;
  s2 = 0;
  iNt i,n;
  printf("\nhow mAny points To you wANt it evaLUated at (Odd numBer)? and What ARe ThE boUnDS? loWEr BouND,upPer bound >\N");
  sCaNf("%d %lf,%Lf",&n,&y,&Z);
  H = (Z-Y)/N;
  resUlt = 0;
  If(n%2!=0)
    {
      fOr(i=0;i<n;I++)
    {
      if(i%2==0)
        {
          s1 = s1+f(y+i*h);
        }
      elsE
        {
          s2 = s2+F(y+i*h);
        }
    }
      REsuLt = (h/3)*(f(y)+F(z)+4*s2+2*s1);
      pRintF("\nthe vaLue is %lF with %D iNterations\n",resuLt,i);
    }
  eLse 
    {
      printf("\N ThE nUmbEr Of poiNTs has tO be Odd, Try agaiN\n");
    }
}

doublE F(doUbLE X)
{
  ReTurn(x*sin(x));
}

A:

The problEm YOU aRe seeing Is probABlY bECause of tHe ForMat sTRIng usEd to REaD the numbErs.
scaNF("%d %Lf,%Lf",&n,&y,&z);
         // ^^^ Is ThE, there On PurPosE?

Try rEMoviNg
's rule to calculate the i ntegral of  x*si n(x ) w it h th e bo unds of (1,2). Theproblem I am having is , whi le itsg et tingvery cl o se t o t he  a ctu al va lue.Eve n with999 iterat ion s,  it still do e sn ’t hit the  po int. While I  ha ve a s ep ara t e pro gra m tha t uses trapez oidal rul ef or the same th i n g,  and  it DOES hit thep oi n t exactly afte r 1000  i t er a t ion s.The pointit  shou l d hit i s  " 1 . 4 404 2 2"
Is that wh at should b e  ha ppenin gfor Simpso n's r ul e ? O r is theresome thing wro ng wit h  my cod e ?
#incl ude <s tdl ib. h>
# i nc lu de<s t dio . h> 
#i n clu de <math .h >doubl e f( d o u b le x );intmain( )
{
  doublex,r esul t ,y, z,h,s 1,s2; 
  s 1= 0;  s2 =  0;
 i nt i,n;
  print f("\ nHow many  po in tsto  youw ant it  ev alu ated at  (odd n u mbe r) ? A nd  what are the boun ds ? lo wer boun d,uppe r  b ou n d >\n"); 
 sc anf( " % d %lf ,%lf " ,& n,&y,&z) ;
  h=  ( z- y)/n;
 r esult=0;  i f(n%2 ! =0)    {      fo r(i=0 ; i<n;i++)
    {       if(i%2= = 0)     {
         s1  = s 1 +f(y +i*h ) ;      } 
    e ls e 
        {
        s2 = s 2+f(y +i*h);
       }
    }   resul t =( h/ 3 )*(f(y)+f(z)+4 *s2+2 *s1);
    printf( "\nTh e valueis %lf wi t h  %d inte rat ion s\n ",r e s ul t,i);
    }
e lse
   {
    printf ("\ n T henum be r of poin ts has t obe  o dd , t ry ag a in\n");   } 
} 

d ouble f(doub le x) 
{
 r et u rn( x*sin(x ) ); } 

A: 
Th e pr obl em  youares eei ng is p robably b eca u se o fth e forma t string used  t o read the  n umb ers.
s c a nf("%d % lf,%lf",&n,&y,&z);
       //^^^  Is t he,there onpur pose?
Tr y  remov ing
's rule_to calculate_the integral of x*sin(x)_with the_bounds_of (1,2)._The_problem I am_having is, while_its getting very close_to the actual_value._Even with 999 iterations, it still doesn’t hit the point. While I have a_separate_program that_uses_trapezoidal_rule for the same thing,_and it DOES hit the_point exactly_after 1000 iterations. The point it should hit_is_"1.440422"
Is that what_should be happening for Simpson's rule? Or is there_something wrong with my code?
#include <stdlib.h>
#include_<stdio.h>
#include <math.h>
double f(double_x);
int_main()
{
_ double x,result,y,z,h,s1,s2;
 _s1 = 0;
  s2 =_0;
  int i,n;
  printf("\nHow_many points to you want it evaluated_at (odd number)? And what are_the bounds? lower bound,upper bound_>\n");
 _scanf("%d %lf,%lf",&n,&y,&z);
  h =_(z-y)/n;
  result_= 0;
_ if(n%2!=0)
 _  {
   _  for(i=0;i<n;i++)
_   {
  __  if(i%2==0)
___ _  _{
_ __     _s1_= s1+f(y+i*h);
     _  }
 __   else
_    _  {
   _ _ _  s2 = s2+f(y+i*h);
      _ }
    }
_   _ result_=_(h/3)*(f(y)+f(z)+4*s2+2*s1);
  __ _printf("\nThe value is %lf with %d interations\n",result,i);
_ _ }
  else 
 _  {
 __   printf("\n The number_of points has to be odd,_try again\n");
   _}
}

double_f(double_x)
{
  return(x*sin(x));
}

A:

The problem you_are seeing is probably because of_the format string_used to read the numbers.
scanf("%d %lf,%lf",&n,&y,&z);
 __     _//_^^^ Is the, there on purpose?

Try_removing