title: Returning a tuple from a function in C
body: <p>I need some hint for implementing this algorithm in C. This is a maximum subarray problem. I have made the polynomial time program and also linear time program. I am new to C so I don't know how to return multiple values from a function as this algorithm requires it. For example this line in the algorithm <strong>(left-low,left-high,left-sum)=FIND-MAXIMUM-SUBARRAY(A,low,mid)</strong> where <strong>FIND-MAX-SUBARRAY(A,low,mid)</strong> is a recursive function call.</p>
  
  <p>This is the algorithm from coremen:</p>
  
  <p><img src="https://i.stack.imgur.com/k2CAb.png" alt="Algorithm from coremen"></p>
  
  <p>Below I have set the global variables <strong>cross-low,cross-high,cross-sum</strong> . How can I do the same for <strong>left-low,left-high,left-sum</strong> and <strong>right-low,right-high,right-sum</strong>?</p>
  
  <pre><code>#include "max_subarray_common.h"
  #define SENTINAL -3000
  
  int left_low,left_high,left_sum;
  int right_low,right_high,right_sum;
  int cross_low,cross_high,cross_sum;
  
  
  void max_crossing_subarray(int low,int mid,int high)
  {
      int left_sum=SENTINAL;
      int sum=0;
      int max_left=low,max_right=high;
      for(int i=mid;i&gt;=low;i--)
      {
          sum=sum+change[i];
          if(sum&gt;left_sum)
          {
              left_sum=sum;
              max_left=i;
          }
      }
      int right_sum=0;
      sum=0;
      for(int j=mid+1;j&lt;=high;j++)
      {
          sum=sum+change[j];
          if(sum&gt;right_sum)
          {
              right_sum=sum;
              max_right=j;
          }
      }
      cross_low=max_left;
      cross_high=max_right;
      cross_sum=left_sum+right_sum;
  }
  </code></pre>
  
  <p>This is my header file:</p>
  
  <pre><code>#ifndef max_subarray_h
  #define max_subarray_h
  
  #include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;time.h&gt;
  
  extern int price[];
  extern int n;
  extern int change[];
  extern int from;
  extern int to;
  extern int max;
  
  
  void init_change();
  void max_subarray_poly();
  void max_subarray_crossing();
  void max_subarray_rec();
  void max_crossing_subarray();
  
  #endif
  </code></pre>
  
  <p><code>change[]</code> is the array for which the subarray is to be found. Also my output should look like this:</p>
  
  <pre><code>from=8
  to=11
  maximum profit=43
  </code></pre>