Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
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]);
}
question