AR15
QUESTION DESCRIPTION
Ramar has set of numbers and somu has set of numbers.
Now the class instructor is asking to add to sorted arrays.
The task is to merge them in a sorted manner.
Mandatory method should be "void mergeArrays(int arr1[], int arr2[], int n1,int n2, int arr3[])"
Ramar has set of numbers and somu has set of numbers.
Now the class instructor is asking to add to sorted arrays.
The task is to merge them in a sorted manner.
Mandatory method should be "void mergeArrays(int arr1[], int arr2[], int n1,int n2, int arr3[])"
TEST CASE 2
INPUT
INPUT
5 6
1 2 4 9 15
2 3 7 8 18 20
OUTPUT1 2 2 3 4 7 8 9 15 18 20
#include <stdio.h>
void mergeArrays(int arr1[], int arr2[], int n1,int n2, int arr3[])
{
int i,j;
for(i=0;i<(n1+n2);i++)
{
if(i<n1)
arr3[i]=arr1[i];
else
arr3[i]=arr2[i-n1];
}
for(i=0;i<n1+n2-1;i++)
{
for(j=0;j<n1+n2-1-i;j++)
{
if(arr3[j]>arr3[j+1])
{
int temp=arr3[j];
arr3[j]=arr3[j+1];
arr3[j+1]=temp;
}
}
}//sorting completed
for(i=0;i<n1+n2;i++)
printf("%d ",arr3[i]);
}
int main() {
int n1, n2,i,j;
scanf("%d %d", &n1, &n2);
int arr1[n1], arr2[n2],arr3[n1+n2];
for(i=0;i<n1;i++)
scanf("%d",&arr1[i]);
for(i=0;i<n2;i++)
scanf("%d", &arr2[i]);
mergeArrays(arr1,arr2,n1,n2,arr3);
return 0;
}
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteSnowflake Training in Bangalore
Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man learn
ReplyDeletePega Training
output is correct. but its n ot 100% evoluvate
ReplyDeleteonly 75 persent evoluvate