C Program For Merge Sort

/*Merge Sort*/

#include<stdio.h>
#include<conio.h>
main()
{
int a[10],b[10],c[20],i,j,k,n,n1;
clrscr();
printf("Enter the sizes of the arrays\n");
scanf("%d%d",&n,&n1);
 for(i=0;i<n;i++)
 {
 printf("Enter the values of a[%d]",i);
 scanf("%d",&a[i]);
 }

 for(j=0;j<n1;j++)
 {
 printf("Enter the value of b[%d]",j);
 scanf("%d",&b[j]);
 }

i=0; j=0; k=0;
 while((i<n)&&(j<n1))
 {
  if (a[i]<b[j])
  {
  c[k]=a[i];
  k++;
  i++;
  }
  else
  {
  c[k]=b[j];
  k++;
  j++;
  }
 }

while(i<n)
{
c[k]=a[i];
k++;
i++;
}

while(j<n1)
{
c[k]=b[j];
k++;
j++;
}

printf("The final array after the sorting is \n");
 for(i=0;i<n+n1;i++)
 {
 printf("c[%d]=%d\n",i,c[i]);
 }
}
Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Web Developer, Student and Mechanical Engineer. He Enjoys writing articles, Blogging, Solving Errors and Social Networking. Feel Free to let me know any of your concerns about hacking or let me know if you need any more methods on hacking anything. Enjoy Learning

No comments:

Post a Comment