S
sj
Hi,
I am new to C and learning it. could someone help me to understand the
following code's output? I am having hard time understanding how n2
values like that?. To me all n2 values are equal to 1. What am i
missing here?
thanks in advance.
output:
n1 = 8
n1 = 4
n1 = 2
n2 = 2
n2 = 4
n2 = 8
code:
#include <stdio.h>
#define MAX 8
void msort(int list[], int n)
{
int half1;
int arr1[MAX/2+1];
int count = 0;
if(n > 1)
{
count++;
half1 = n / 2;
printf("n1 = %d ", n);
printf(" \n");
msort(arr1, half1);
printf("n2 = %d ", n);
printf(" \n");
}
}
int main()
{
int n = 8;
int array[] = { 8, 3, 2, 9, 7, 1, 5, 4 };
msort(array, n);
return 0;
}
I am new to C and learning it. could someone help me to understand the
following code's output? I am having hard time understanding how n2
values like that?. To me all n2 values are equal to 1. What am i
missing here?
thanks in advance.
output:
n1 = 8
n1 = 4
n1 = 2
n2 = 2
n2 = 4
n2 = 8
code:
#include <stdio.h>
#define MAX 8
void msort(int list[], int n)
{
int half1;
int arr1[MAX/2+1];
int count = 0;
if(n > 1)
{
count++;
half1 = n / 2;
printf("n1 = %d ", n);
printf(" \n");
msort(arr1, half1);
printf("n2 = %d ", n);
printf(" \n");
}
}
int main()
{
int n = 8;
int array[] = { 8, 3, 2, 9, 7, 1, 5, 4 };
msort(array, n);
return 0;
}