Posts

Showing posts from September, 2022

Degree 2nd Sem cs programs

  1. C program to merge sort ALGORITHM divide and conquer PROGRAM #include<stdio.h> void mergesort( int a [], int i , int j ); void merge( int a [], int i1 , int j1 , int i2 , int j2 ); int main(){     int a[30],n,i;     printf("enter no. of elements");     scanf("%d",&n);     printf("enter array elements");     for(i=0;i<n;i++)         scanf("%d",&a[i]);     mergesort(a,0,n-1);     printf("\nsorted array is : ");     for(i=0;i<n;i++)         printf("%d",a[i]);     return 0; } void mergesort( int a [], int i , int j ){     int mid;     if( i < j ){         mid=( i + j )/2;         printf("mid before first call is %d\t%d\t%d\n",mid, i , j );         mergesort( a , i ,mid);         printf("mid after first call is %d\t%d\n",mid, i );         mergesort( a ,mid+1, j );         printf("mid after second call is %d\t%d\n",mid, j );         merge( a , i ,mid,mid+1,