Write a program in C to merge two arrays of same size sorted in descending order...

TASK-

Write a program in C to merge two arrays of same size sorted in descending order...

  • We have to Arrange these to arrays in one array
  • Then sort all array in descending order
  • Descending order: Largest number to smaller.

CODE:

#include<stdio.h>
int main(){
int a,b,c=0;
printf("Enter the number of elements in each array ");
scanf("%d",&a);//Taking size!!! as size of both arrays is same so we will take size just once
int one[a],two[a]; //SEE HERE we used a for both sizes
	int merge[2*a];//Here is an array which will be used for merging
	printf("Enter the values in arrays\n");
	//Taking numbers in both array 
for (b=0;b<=(a-1);b++)
{
	//First we will as for array1
	printf("Enter the value of %d entry of 1st array: ",b+1);
	scanf("%d",&one[b]); //Entry entered
	//Here the number goes in merging array AND index of merging arrays is controlled by c;
	merge[c]=one[b];
	c++; //Index increases
	//Same for Array2
	printf("Enter the value of %d entry of 2nd array: ",b+1);
	scanf("%d",&two[b]);
	//Again value of array2 is also entered in merging array; 
	merge[c]=two[b];
	c++;
}
/*
Now!!!We Have Made merge array now we Will sort it in descending order*/
for(int i=0;i<(2*a);i++)      
   {
       int temp;//it is taken for swamping numbers!!!
       for(int j=i+1; j<(2*a) ;j++)
        {
            if(merge[i]<merge[j])
            {
                temp=merge[i]; 
                merge[i]=merge[j];
                merge[j]=temp;
            }
        }
    }
	printf("\n");
	//Now all work done now print the result:
	for (b=0;b<(a+a);b++)
	printf("%d",merge[b]);
	getchar();
	return 0;
}

Expected Output:



NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

5 Comments

  1. Nice sir, please made a take transpose matrix

    ReplyDelete
    Replies
    1. Its already there. Follow the Link given below

      https://let-us-c-the-program.blogspot.com/2022/01/write-c-program-to-find-transpose-of.html

      Delete
  2. Thanx for uploading you are the best blogger.

    ReplyDelete
Post a Comment
Previous Post Next Post