-2

It's program of sort and merge two arrays.(in C)
When i enter 1 to 10 randomly that doesn't give me output like 1,2,3..10.
WHY?

CODE:
#include <stdio.h>
void main()
{
int i, j, n;
int arr1[5];
int arr2[5];
int ans[10];

for (i = 0; i < 5; i++)
scanf("%d", &arr1[i]);
for (i = 5; i < 10; i++)
scanf("%d", &arr2[i]);

for (i = 0; i < 10; i++)
{
if (i < 5)
ans[i] = arr1[i];
else
ans[i] = arr2[i];
printf("%d ", ans[i]);
}
printf("\n");
for (i = 0; i < 10; i++)
{
for (j = 0; j < 10; j++)
{
if (ans[j] > ans[j + 1])
{
n = ans[j + 1];
ans[j + 1] = ans[j];
ans[j] = n;
}
}
}
for (i = 0; i < 10; i++)
printf("%d ", ans[i]);
}

Comments
  • 6
    Again, do your fucking homework yourself, you moron.
  • 1
    Okay enough. Fuck off now
  • 3
    This is for-loop hell
  • 1
    look up what a "debugger" is and use that. You'll be able to step through the program one line at a time and you can see what's happening.
Add Comment