Function returns -1.#IND00 + merging functions












0















so i'm basically trying to merge following 3 functions in 1 (thats what my teacher wants, but i couldnt get it to work so i did 3)



#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define TOTAL_DEG (180.0)


double berechnung_length(double a, double b, double c, double gamma)
{
c = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
return c;
}

double berechnung_alpha(double a, double b, double c, double gamma, double alpha)
{
alpha = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
return alpha;
}

double berechnung_beta(double gamma, double alpha, double beta)
{
beta = - gamma - alpha + TOTAL_DEG;
return beta;
}


soo, how can i get the function to return the values if its just 1 function (pointers would be an option but im not so comfy with them yet)



Thanks for the help!










share|improve this question


















  • 1





    what about building a struct with c, alpha and beta and working with a pointer to the struct.

    – Mike
    Nov 22 '18 at 13:51











  • Note: acos((double )(b * b + c * c - a * a) / (2.0 * b * c)); is a problem when the quotient is close to 1.0, -1.0. Due to double math details, sometimes the result is just over 1.0 or under -1.0, even though the mathematical answer would not allow that.

    – chux
    Nov 22 '18 at 13:51











  • acos() returns radians. alpha + TOTAL_DEG likely wrong.

    – chux
    Nov 22 '18 at 13:52
















0















so i'm basically trying to merge following 3 functions in 1 (thats what my teacher wants, but i couldnt get it to work so i did 3)



#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define TOTAL_DEG (180.0)


double berechnung_length(double a, double b, double c, double gamma)
{
c = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
return c;
}

double berechnung_alpha(double a, double b, double c, double gamma, double alpha)
{
alpha = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
return alpha;
}

double berechnung_beta(double gamma, double alpha, double beta)
{
beta = - gamma - alpha + TOTAL_DEG;
return beta;
}


soo, how can i get the function to return the values if its just 1 function (pointers would be an option but im not so comfy with them yet)



Thanks for the help!










share|improve this question


















  • 1





    what about building a struct with c, alpha and beta and working with a pointer to the struct.

    – Mike
    Nov 22 '18 at 13:51











  • Note: acos((double )(b * b + c * c - a * a) / (2.0 * b * c)); is a problem when the quotient is close to 1.0, -1.0. Due to double math details, sometimes the result is just over 1.0 or under -1.0, even though the mathematical answer would not allow that.

    – chux
    Nov 22 '18 at 13:51











  • acos() returns radians. alpha + TOTAL_DEG likely wrong.

    – chux
    Nov 22 '18 at 13:52














0












0








0








so i'm basically trying to merge following 3 functions in 1 (thats what my teacher wants, but i couldnt get it to work so i did 3)



#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define TOTAL_DEG (180.0)


double berechnung_length(double a, double b, double c, double gamma)
{
c = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
return c;
}

double berechnung_alpha(double a, double b, double c, double gamma, double alpha)
{
alpha = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
return alpha;
}

double berechnung_beta(double gamma, double alpha, double beta)
{
beta = - gamma - alpha + TOTAL_DEG;
return beta;
}


soo, how can i get the function to return the values if its just 1 function (pointers would be an option but im not so comfy with them yet)



Thanks for the help!










share|improve this question














so i'm basically trying to merge following 3 functions in 1 (thats what my teacher wants, but i couldnt get it to work so i did 3)



#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define TOTAL_DEG (180.0)


double berechnung_length(double a, double b, double c, double gamma)
{
c = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
return c;
}

double berechnung_alpha(double a, double b, double c, double gamma, double alpha)
{
alpha = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
return alpha;
}

double berechnung_beta(double gamma, double alpha, double beta)
{
beta = - gamma - alpha + TOTAL_DEG;
return beta;
}


soo, how can i get the function to return the values if its just 1 function (pointers would be an option but im not so comfy with them yet)



Thanks for the help!







c function pointers






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '18 at 13:44









OofOof

42




42








  • 1





    what about building a struct with c, alpha and beta and working with a pointer to the struct.

    – Mike
    Nov 22 '18 at 13:51











  • Note: acos((double )(b * b + c * c - a * a) / (2.0 * b * c)); is a problem when the quotient is close to 1.0, -1.0. Due to double math details, sometimes the result is just over 1.0 or under -1.0, even though the mathematical answer would not allow that.

    – chux
    Nov 22 '18 at 13:51











  • acos() returns radians. alpha + TOTAL_DEG likely wrong.

    – chux
    Nov 22 '18 at 13:52














  • 1





    what about building a struct with c, alpha and beta and working with a pointer to the struct.

    – Mike
    Nov 22 '18 at 13:51











  • Note: acos((double )(b * b + c * c - a * a) / (2.0 * b * c)); is a problem when the quotient is close to 1.0, -1.0. Due to double math details, sometimes the result is just over 1.0 or under -1.0, even though the mathematical answer would not allow that.

    – chux
    Nov 22 '18 at 13:51











  • acos() returns radians. alpha + TOTAL_DEG likely wrong.

    – chux
    Nov 22 '18 at 13:52








1




1





what about building a struct with c, alpha and beta and working with a pointer to the struct.

– Mike
Nov 22 '18 at 13:51





what about building a struct with c, alpha and beta and working with a pointer to the struct.

– Mike
Nov 22 '18 at 13:51













Note: acos((double )(b * b + c * c - a * a) / (2.0 * b * c)); is a problem when the quotient is close to 1.0, -1.0. Due to double math details, sometimes the result is just over 1.0 or under -1.0, even though the mathematical answer would not allow that.

– chux
Nov 22 '18 at 13:51





Note: acos((double )(b * b + c * c - a * a) / (2.0 * b * c)); is a problem when the quotient is close to 1.0, -1.0. Due to double math details, sometimes the result is just over 1.0 or under -1.0, even though the mathematical answer would not allow that.

– chux
Nov 22 '18 at 13:51













acos() returns radians. alpha + TOTAL_DEG likely wrong.

– chux
Nov 22 '18 at 13:52





acos() returns radians. alpha + TOTAL_DEG likely wrong.

– chux
Nov 22 '18 at 13:52












3 Answers
3






active

oldest

votes


















0















to merge following 3 functions in 1




Using OP's existing function calls:



void berechnung_all(double a, double b, double c, double gamma,
double *length, double *alpha, double *beta) {
*length = berechnung_length(a,b,c,gamma);
*alpha = berechnung_alpha(a,b,c,gamma, 0);
*beta = berechnung_beta(a,b,c,gamma, *alpha, 0);
}




Tighter integration



#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif

#define R2D(r) ((r)*180.0/M_PI)
#define D2R(r) ((r)/180.0*M_PI)

void berechnung_all(double a, double b, double c, double gamma,
double *length, double *alpha, double *beta) {

*length = sqrt(a * a + b * b - (2 * a * b * cos(D2R(gamma))));

// Avoid direct call to `acos()`: prevent `double` math oddities just outside [-1.0...1.0]
double x = (b * b + c * c - a * a) / (2.0 * b * c);
if (x > 1.0) x = 1.0;
if (x < -1.0) x = -1.0;
*alpha = R2D(gamma * acos(x));

#define TOTAL_DEG (180.0)
*beta = - gamma - alpha + TOTAL_DEG;
}





share|improve this answer































    0














    You can have an enumeration for the different operations and switch on that enum to perform different operations in your versatile function. Something like this:



    #include <stdio.h>
    #include <math.h>
    #include <stdlib.h>
    #define TOTAL_DEG (180.0)

    enum oper {LENGTH, ALPHA, BETA};

    double berechnung_any(double a, double b, double c, double gamma, enum oper op)
    {
    double retVal;
    switch(op) {
    case LENGTH:
    retVal = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
    break;
    case ALPHA:
    retVal = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
    break;
    case BETA:
    retVal = - gamma - (gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c))) + TOTAL_DEG;
    break;
    }
    return retVal;
    }





    share|improve this answer































      0














      ok, so i am assuming you already have variables a,b in hand and you don't have c, alpha and beta, but you want to have them after the calculation.
      here is the code, i added a main function to demonstrate u how to use pointers.



      #include <stdio.h>
      #include <math.h>
      #include <stdlib.h>
      #define TOTAL_DEG (180.0)

      //here a and b are transferred by values, c, gamma and alpha are just pointers.
      double berechnung_func(double a, double b, double* c, double* gamma, double* alpha){

      *c = sqrt(a * a + b * b - (2 * a * b * cos(*gamma)));
      *alpha = (*gamma) * acos((double )(b * b + (*c) * (*c) - a * a) / (2.0 * b * (*c)));

      return (- (*gamma) - (*alpha) + TOTAL_DEG);
      }

      int main()
      {
      double c, gamma, alpha, beta, a=5, b=6;

      // here we are sending c, gamma and alpha **addresses** to the function.
      beta = berechnung_func(a, b, &c, &gamma, &alpha);
      printf("c = %dn gamma = %dn alpha = %dn beta = %dn", c, gamma, alpha, beta);

      return 0;
      }





      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432349%2ffunction-returns-1-ind00-merging-functions%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0















        to merge following 3 functions in 1




        Using OP's existing function calls:



        void berechnung_all(double a, double b, double c, double gamma,
        double *length, double *alpha, double *beta) {
        *length = berechnung_length(a,b,c,gamma);
        *alpha = berechnung_alpha(a,b,c,gamma, 0);
        *beta = berechnung_beta(a,b,c,gamma, *alpha, 0);
        }




        Tighter integration



        #ifndef M_PI
        #define M_PI 3.1415926535897932384626433832795
        #endif

        #define R2D(r) ((r)*180.0/M_PI)
        #define D2R(r) ((r)/180.0*M_PI)

        void berechnung_all(double a, double b, double c, double gamma,
        double *length, double *alpha, double *beta) {

        *length = sqrt(a * a + b * b - (2 * a * b * cos(D2R(gamma))));

        // Avoid direct call to `acos()`: prevent `double` math oddities just outside [-1.0...1.0]
        double x = (b * b + c * c - a * a) / (2.0 * b * c);
        if (x > 1.0) x = 1.0;
        if (x < -1.0) x = -1.0;
        *alpha = R2D(gamma * acos(x));

        #define TOTAL_DEG (180.0)
        *beta = - gamma - alpha + TOTAL_DEG;
        }





        share|improve this answer




























          0















          to merge following 3 functions in 1




          Using OP's existing function calls:



          void berechnung_all(double a, double b, double c, double gamma,
          double *length, double *alpha, double *beta) {
          *length = berechnung_length(a,b,c,gamma);
          *alpha = berechnung_alpha(a,b,c,gamma, 0);
          *beta = berechnung_beta(a,b,c,gamma, *alpha, 0);
          }




          Tighter integration



          #ifndef M_PI
          #define M_PI 3.1415926535897932384626433832795
          #endif

          #define R2D(r) ((r)*180.0/M_PI)
          #define D2R(r) ((r)/180.0*M_PI)

          void berechnung_all(double a, double b, double c, double gamma,
          double *length, double *alpha, double *beta) {

          *length = sqrt(a * a + b * b - (2 * a * b * cos(D2R(gamma))));

          // Avoid direct call to `acos()`: prevent `double` math oddities just outside [-1.0...1.0]
          double x = (b * b + c * c - a * a) / (2.0 * b * c);
          if (x > 1.0) x = 1.0;
          if (x < -1.0) x = -1.0;
          *alpha = R2D(gamma * acos(x));

          #define TOTAL_DEG (180.0)
          *beta = - gamma - alpha + TOTAL_DEG;
          }





          share|improve this answer


























            0












            0








            0








            to merge following 3 functions in 1




            Using OP's existing function calls:



            void berechnung_all(double a, double b, double c, double gamma,
            double *length, double *alpha, double *beta) {
            *length = berechnung_length(a,b,c,gamma);
            *alpha = berechnung_alpha(a,b,c,gamma, 0);
            *beta = berechnung_beta(a,b,c,gamma, *alpha, 0);
            }




            Tighter integration



            #ifndef M_PI
            #define M_PI 3.1415926535897932384626433832795
            #endif

            #define R2D(r) ((r)*180.0/M_PI)
            #define D2R(r) ((r)/180.0*M_PI)

            void berechnung_all(double a, double b, double c, double gamma,
            double *length, double *alpha, double *beta) {

            *length = sqrt(a * a + b * b - (2 * a * b * cos(D2R(gamma))));

            // Avoid direct call to `acos()`: prevent `double` math oddities just outside [-1.0...1.0]
            double x = (b * b + c * c - a * a) / (2.0 * b * c);
            if (x > 1.0) x = 1.0;
            if (x < -1.0) x = -1.0;
            *alpha = R2D(gamma * acos(x));

            #define TOTAL_DEG (180.0)
            *beta = - gamma - alpha + TOTAL_DEG;
            }





            share|improve this answer














            to merge following 3 functions in 1




            Using OP's existing function calls:



            void berechnung_all(double a, double b, double c, double gamma,
            double *length, double *alpha, double *beta) {
            *length = berechnung_length(a,b,c,gamma);
            *alpha = berechnung_alpha(a,b,c,gamma, 0);
            *beta = berechnung_beta(a,b,c,gamma, *alpha, 0);
            }




            Tighter integration



            #ifndef M_PI
            #define M_PI 3.1415926535897932384626433832795
            #endif

            #define R2D(r) ((r)*180.0/M_PI)
            #define D2R(r) ((r)/180.0*M_PI)

            void berechnung_all(double a, double b, double c, double gamma,
            double *length, double *alpha, double *beta) {

            *length = sqrt(a * a + b * b - (2 * a * b * cos(D2R(gamma))));

            // Avoid direct call to `acos()`: prevent `double` math oddities just outside [-1.0...1.0]
            double x = (b * b + c * c - a * a) / (2.0 * b * c);
            if (x > 1.0) x = 1.0;
            if (x < -1.0) x = -1.0;
            *alpha = R2D(gamma * acos(x));

            #define TOTAL_DEG (180.0)
            *beta = - gamma - alpha + TOTAL_DEG;
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 '18 at 14:06









            chuxchux

            83.6k872152




            83.6k872152

























                0














                You can have an enumeration for the different operations and switch on that enum to perform different operations in your versatile function. Something like this:



                #include <stdio.h>
                #include <math.h>
                #include <stdlib.h>
                #define TOTAL_DEG (180.0)

                enum oper {LENGTH, ALPHA, BETA};

                double berechnung_any(double a, double b, double c, double gamma, enum oper op)
                {
                double retVal;
                switch(op) {
                case LENGTH:
                retVal = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
                break;
                case ALPHA:
                retVal = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
                break;
                case BETA:
                retVal = - gamma - (gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c))) + TOTAL_DEG;
                break;
                }
                return retVal;
                }





                share|improve this answer




























                  0














                  You can have an enumeration for the different operations and switch on that enum to perform different operations in your versatile function. Something like this:



                  #include <stdio.h>
                  #include <math.h>
                  #include <stdlib.h>
                  #define TOTAL_DEG (180.0)

                  enum oper {LENGTH, ALPHA, BETA};

                  double berechnung_any(double a, double b, double c, double gamma, enum oper op)
                  {
                  double retVal;
                  switch(op) {
                  case LENGTH:
                  retVal = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
                  break;
                  case ALPHA:
                  retVal = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
                  break;
                  case BETA:
                  retVal = - gamma - (gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c))) + TOTAL_DEG;
                  break;
                  }
                  return retVal;
                  }





                  share|improve this answer


























                    0












                    0








                    0







                    You can have an enumeration for the different operations and switch on that enum to perform different operations in your versatile function. Something like this:



                    #include <stdio.h>
                    #include <math.h>
                    #include <stdlib.h>
                    #define TOTAL_DEG (180.0)

                    enum oper {LENGTH, ALPHA, BETA};

                    double berechnung_any(double a, double b, double c, double gamma, enum oper op)
                    {
                    double retVal;
                    switch(op) {
                    case LENGTH:
                    retVal = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
                    break;
                    case ALPHA:
                    retVal = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
                    break;
                    case BETA:
                    retVal = - gamma - (gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c))) + TOTAL_DEG;
                    break;
                    }
                    return retVal;
                    }





                    share|improve this answer













                    You can have an enumeration for the different operations and switch on that enum to perform different operations in your versatile function. Something like this:



                    #include <stdio.h>
                    #include <math.h>
                    #include <stdlib.h>
                    #define TOTAL_DEG (180.0)

                    enum oper {LENGTH, ALPHA, BETA};

                    double berechnung_any(double a, double b, double c, double gamma, enum oper op)
                    {
                    double retVal;
                    switch(op) {
                    case LENGTH:
                    retVal = sqrt(a * a + b * b - (2 * a * b * cos(gamma)));
                    break;
                    case ALPHA:
                    retVal = gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c));
                    break;
                    case BETA:
                    retVal = - gamma - (gamma * acos((double )(b * b + c * c - a * a) / (2.0 * b * c))) + TOTAL_DEG;
                    break;
                    }
                    return retVal;
                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 22 '18 at 14:06









                    P.WP.W

                    15.5k31453




                    15.5k31453























                        0














                        ok, so i am assuming you already have variables a,b in hand and you don't have c, alpha and beta, but you want to have them after the calculation.
                        here is the code, i added a main function to demonstrate u how to use pointers.



                        #include <stdio.h>
                        #include <math.h>
                        #include <stdlib.h>
                        #define TOTAL_DEG (180.0)

                        //here a and b are transferred by values, c, gamma and alpha are just pointers.
                        double berechnung_func(double a, double b, double* c, double* gamma, double* alpha){

                        *c = sqrt(a * a + b * b - (2 * a * b * cos(*gamma)));
                        *alpha = (*gamma) * acos((double )(b * b + (*c) * (*c) - a * a) / (2.0 * b * (*c)));

                        return (- (*gamma) - (*alpha) + TOTAL_DEG);
                        }

                        int main()
                        {
                        double c, gamma, alpha, beta, a=5, b=6;

                        // here we are sending c, gamma and alpha **addresses** to the function.
                        beta = berechnung_func(a, b, &c, &gamma, &alpha);
                        printf("c = %dn gamma = %dn alpha = %dn beta = %dn", c, gamma, alpha, beta);

                        return 0;
                        }





                        share|improve this answer




























                          0














                          ok, so i am assuming you already have variables a,b in hand and you don't have c, alpha and beta, but you want to have them after the calculation.
                          here is the code, i added a main function to demonstrate u how to use pointers.



                          #include <stdio.h>
                          #include <math.h>
                          #include <stdlib.h>
                          #define TOTAL_DEG (180.0)

                          //here a and b are transferred by values, c, gamma and alpha are just pointers.
                          double berechnung_func(double a, double b, double* c, double* gamma, double* alpha){

                          *c = sqrt(a * a + b * b - (2 * a * b * cos(*gamma)));
                          *alpha = (*gamma) * acos((double )(b * b + (*c) * (*c) - a * a) / (2.0 * b * (*c)));

                          return (- (*gamma) - (*alpha) + TOTAL_DEG);
                          }

                          int main()
                          {
                          double c, gamma, alpha, beta, a=5, b=6;

                          // here we are sending c, gamma and alpha **addresses** to the function.
                          beta = berechnung_func(a, b, &c, &gamma, &alpha);
                          printf("c = %dn gamma = %dn alpha = %dn beta = %dn", c, gamma, alpha, beta);

                          return 0;
                          }





                          share|improve this answer


























                            0












                            0








                            0







                            ok, so i am assuming you already have variables a,b in hand and you don't have c, alpha and beta, but you want to have them after the calculation.
                            here is the code, i added a main function to demonstrate u how to use pointers.



                            #include <stdio.h>
                            #include <math.h>
                            #include <stdlib.h>
                            #define TOTAL_DEG (180.0)

                            //here a and b are transferred by values, c, gamma and alpha are just pointers.
                            double berechnung_func(double a, double b, double* c, double* gamma, double* alpha){

                            *c = sqrt(a * a + b * b - (2 * a * b * cos(*gamma)));
                            *alpha = (*gamma) * acos((double )(b * b + (*c) * (*c) - a * a) / (2.0 * b * (*c)));

                            return (- (*gamma) - (*alpha) + TOTAL_DEG);
                            }

                            int main()
                            {
                            double c, gamma, alpha, beta, a=5, b=6;

                            // here we are sending c, gamma and alpha **addresses** to the function.
                            beta = berechnung_func(a, b, &c, &gamma, &alpha);
                            printf("c = %dn gamma = %dn alpha = %dn beta = %dn", c, gamma, alpha, beta);

                            return 0;
                            }





                            share|improve this answer













                            ok, so i am assuming you already have variables a,b in hand and you don't have c, alpha and beta, but you want to have them after the calculation.
                            here is the code, i added a main function to demonstrate u how to use pointers.



                            #include <stdio.h>
                            #include <math.h>
                            #include <stdlib.h>
                            #define TOTAL_DEG (180.0)

                            //here a and b are transferred by values, c, gamma and alpha are just pointers.
                            double berechnung_func(double a, double b, double* c, double* gamma, double* alpha){

                            *c = sqrt(a * a + b * b - (2 * a * b * cos(*gamma)));
                            *alpha = (*gamma) * acos((double )(b * b + (*c) * (*c) - a * a) / (2.0 * b * (*c)));

                            return (- (*gamma) - (*alpha) + TOTAL_DEG);
                            }

                            int main()
                            {
                            double c, gamma, alpha, beta, a=5, b=6;

                            // here we are sending c, gamma and alpha **addresses** to the function.
                            beta = berechnung_func(a, b, &c, &gamma, &alpha);
                            printf("c = %dn gamma = %dn alpha = %dn beta = %dn", c, gamma, alpha, beta);

                            return 0;
                            }






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 22 '18 at 14:14









                            asafrubasafrub

                            1




                            1






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432349%2ffunction-returns-1-ind00-merging-functions%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                MongoDB - Not Authorized To Execute Command

                                Npm cannot find a required file even through it is in the searched directory

                                in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith