Thread: finding area of ellipse

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    24

    finding area of ellipse

    so here is my code


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
        double k,A,B,NumberOfSlices,Width,y,Area;
    
        NumberOfSlices = 10.0;
        Area = 0.0;
        A = 10.0;
        B = 6.0;
        Width = A / NumberOfSlices;
        
        while ( k < NumberOfSlices )
        {
            y = (B/A)*pow(A*A-(Width * ( k + 1 ) * Width * ( k + 1 ),(1.0/2.0));
            Area = y * Width + Area;
            k = k + 1;
        }
        printf("\n\t the area of the ellipse is %10.3f", Area * 4 );
    
    
        printf("\n\n\n");
    }
    i cant get it to give me an answer other than 0.000

    the real answer is 188.4955...but that is by pi * a * b in which a&b are where the ellipse touches the x&y respectively graph axis.

    but i have to calculate using the formula of (x^2/a^2) + (y^2/b^2) = 1 and Area = y * width. please help me.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    For one, you've never initialized k.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
        double k,A,B,W,NumberOfSlices,Width,y,Area,Sum;
    
        NumberOfSlices = 11.0;
        Area = 0.0;
        A = 10.0;
        B = 6.0;
        Width = A / NumberOfSlices;
        k = 0.0;
        Sum = 0.0;
        
        while ( k < NumberOfSlices )
        {
            W = ( Width * ( k + 1 ));
            y = (B/A)*sqrt(A*A-W*W);
            Area = y * Width + Area;
            Sum = Sum + Area;
            k = k + 1;
        }
        printf("\n\t the area of the ellipse is %10.3f",Sum );
    
    
        printf("\n\n\n");
    }
    thats the new one, but the numbers increase as # of slices increases, though it should be becoming smaller. the first with 10 slices was 285, the next, with 12 slices, was 312. and it just continues to rise. i need it to get closer and closer to 188.4955...

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    w8 think i figured it out., removing the + area part on area =

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    24
    YAY ALLS I NEEDED NOW WAS TO PUT SUM * 4 AND ADD SOME 000 ONTO THE # OF SLICES AND YEs! wow im such an idiot for not realize it sooner. thankk you so much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. area of a circle
    By wise_ron in forum C Programming
    Replies: 2
    Last Post: 10-02-2006, 03:15 PM
  2. very weird problem (pointers I think)
    By hannibar in forum C Programming
    Replies: 2
    Last Post: 10-11-2005, 06:45 AM
  3. Helping out a friend...
    By rhymewithnothin in forum C Programming
    Replies: 21
    Last Post: 09-15-2005, 08:59 PM
  4. Need help with switch
    By 3kgt in forum C Programming
    Replies: 2
    Last Post: 02-26-2003, 12:43 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM