Thread: Need sum help with my simple programmes please

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    11

    Need sum help with my simple programmes please

    The Qs are below, and as u can c ive started both Qs but dunno how to finish them ..any help would appreciated thanks

    1) C programme for iinverse of cos-rule
    where cosA = (b^2+c^2-a^2)/2bc
    Last edited by jack0; 04-27-2010 at 01:50 AM.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Can you be a little more specific in regard to the second question? What exactly are you having trouble doing?

    As for the first, it is pretty difficult to compute acosine(x) manually if that is what you are trying to do. I believe there are already functions in math.h that do that for you.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    In fact there is a function in math.h:

    double acos(double x). That should do it.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    11
    so do i need to rewrite the whole program ?

  5. #5
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Well I dont understand why you are reinventing the wheel here. There is a function acos() that computes what you want to compute in part 1, and it probably does it better than you could. Just #include <math.h> and call that function in your main code where you need to calculate acosine.

    As for part 2 one thing that I would note is that factorial is not a floating pointer value but rather an integer. Approximations of factorials like gamma functions do exist indeed. I am not sure what you are trying to compute there.

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    I personally don't know enough trigonometry to calculate acosine manually, although someone else here may be able to provide a solution to that. However, it's most likely going to be the solution already available to you through the math library.

  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    244
    Do you always have to include #include <math.h> if your using a math function?
    I know I am always suppose to because it is the 'correct' thing to do but I have ran my program by accident (it had sqrt() and pow() in it) and the output was correct without it... I am just curious...

  8. #8
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    You only have to include it if you are using a function declared in it. Including a library file is literally copying and pasting it's contents into your source code. For a listing of the functions included in math.h or any other standard header file for that reason just google its name or open it in your C library and see what's inside it.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Matt, for a long time, compilers have been "smart" about adding in certain header definitions, automatically. Even Turbo C v1.01 does it. < HA! >

    But they won't do it for every definition you might need, so doing it manually is by far the better solution. Actually, Turbo C trips itself up on loading floating point sometimes, even when you include math.h. < EEK! >


  10. #10
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by Adak View Post
    Matt, for a long time, compilers have been "smart" about adding in certain header definitions, automatically. Even Turbo C v1.01 does it. < HA! >

    But they won't do it for every definition you might need, so doing it manually is by far the better solution. Actually, Turbo C trips itself up on loading floating point sometimes, even when you include math.h. < EEK! >

    Adak stop advertising Turbo C, I'll report you!

    Just kidding.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Minimum Positive Subsequence Sum
    By CrazyNorman in forum C++ Programming
    Replies: 2
    Last Post: 09-11-2008, 04:25 AM
  2. Simple Socialising Chat Bots
    By bengreenwood in forum C++ Programming
    Replies: 10
    Last Post: 11-28-2007, 08:42 AM
  3. Simple Math Program
    By RazielX in forum C Programming
    Replies: 3
    Last Post: 03-04-2004, 06:22 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Help please with something pretty simple
    By sweetly in forum C++ Programming
    Replies: 5
    Last Post: 09-17-2003, 10:12 AM