Thread: Unable to find values

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    9

    Unable to find values

    This is the half program posted here .I am stuck at this steps and online debugger is not giving correct answers.The whole program gives correct output though. I want to know the value of mid,low and high passed to the second recursive function msort(a,mid+1,high).
    Code:
    int main()
    {
    int i,low,high,n,a[10];
    printf("how many elements");
    scanf("%d",&n);
    printf("\nEnter the elements");
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    low=0;
    high=n-1;
    msort(a,low,high);
    printf("The sorted array is ");
    for(i=0;i<n;i++)
    printf("\n%d",a[i]);
    return 0;
    }
    msort(int a[],int low,int high)
    {
    int mid;
    if(low<high)
    {
    mid=(low+high)/2;
    msort(a,low,mid); //Untill here I got right values
    msort(a,mid+1,high);// I am stuck over here
    }
    return 0;
    }
    After msort(a,low,mid) work is over. According to me,for next function msort(a,mid+1,high) ,
    the value of mid is 2 then 3,
    the value of low is 3 then 4.
    value of high remains 4.
    Is this right?
    I want to know where I am going wrong.


    The value

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Try turning off code optimization when debugging fails to work like you think it should.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unable to pass values to struct as a byte.
    By raadys in forum C Programming
    Replies: 8
    Last Post: 07-24-2014, 07:27 AM
  2. Replies: 7
    Last Post: 03-19-2010, 12:16 AM
  3. Windows 7: Program unable to find glut/glfw dll?
    By Jake.c in forum Game Programming
    Replies: 1
    Last Post: 10-29-2009, 03:59 PM
  4. Unable to calculate float values
    By CHurst in forum C Programming
    Replies: 2
    Last Post: 12-08-2005, 06:14 PM
  5. find out values
    By poorman in forum C Programming
    Replies: 2
    Last Post: 03-14-2002, 12:22 PM

Tags for this Thread