Results 1 to 2 of 2

Thread: Something is wrong with my C++ code. Plz help

  1. #1
    Join Date
    Oct 2011
    Posts
    3

    Something is wrong with my C++ code. Plz help

    I am trying to use the Simpson's Method to calculate area under the curve using this function 2x^2+x but its not working?

    Can some one help me and fix the problem? Its using Simpson's Method and want user to input a,b and N then calculate the area of the function given 2x^2+x

    [code]
    #include <stdio.h>
    #include <conio.h>
    #include <cstdlib>

    double simpson(double a, double b, int n);
    double fk(double x);
    //**********************************
    int main()
    {

    double a,f,b;
    int n;
    //Duomenys----------------
    printf("Enter value of a, example a=0\n a:");
    scanf("%lf", &a);
    //------------------------
    printf("Enter value of n, example n=7\n n:");
    scanf("%d",&n);
    printf ("Enter Value of b, example b=1\nb:");
    scanf("%lf", &b);
    f=simpson(a ,b , n); // Integralas
    //Rezultatas----------------
    printf("The result is f=%7.2f\n",f);

    }
    //**********************************
    double simpson(double a, double b, int n)
    {
    double c= (a+b)/2.0;
    double h3= abs(b-a)/6.0;
    double result= h3*(fk(a)+4.0*fk(c)+fk(b));
    return result;



    }
    //**********************************
    double fk(double x)
    {
    return x * x;
    }
    /[code]

  2. #2
    Join Date
    Mar 2011
    Posts
    160

    Re: Something is wrong with my C++ code. Plz help

    Are you sure its a C++ code. according to my knowledge its a C code. please correct me if i am wrong...

Similar Threads

  1. Replies: 1
    Last Post: 18-02-2012, 08:15 PM
  2. Vb.net **what Is Wrong With This Code**
    By Programmer666 in forum Software Development
    Replies: 1
    Last Post: 30-12-2011, 03:03 AM
  3. Apple sent me Wrong IMEI/Unlock Code for Iphone 4
    By GPower in forum Portable Devices
    Replies: 5
    Last Post: 27-12-2011, 02:29 PM
  4. Wrong Activation Code, activation issues
    By Lawford in forum Networking & Security
    Replies: 4
    Last Post: 11-04-2010, 12:41 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,942,033.84210 seconds with 17 queries