#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#define MAX1 5
#define MAX2 7
int* arr;
int* create (int size){
int *arr,i;
arr = (int *)malloc (sizeof(int)* size);/*note here size of (int )*size means size of int size no. of times,
size is the no of integers in the array*/
for (i=0;i<size;i++){
printf("Enter the element no. %d:",i+1);
scanf("%d",&arr[i]);
}
printf("\n");
return;
}
void sort (int *arr, int size){
int i,j,temp;
for (i=0;i<size;i++)
for(j=i+1;j<size;j++){
if(arr[i]>arr[j]){
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
void display(int *arr, int size){
int i;
for(i=0;i<size;i++)
printf("%d\t",arr[i]);
printf("\n");
}
int* merge (int *a,int *b){
int *arr;
int i,k,j;
int size= MAX1+MAX2;
arr=(int *)malloc(sizeof(int)*size);
for(i=0,j=0,k=0; k<size; k++){
if(a[i]<b[j]){
arr[k]=a[i];
i++;
if (i==MAX1){
for (;j<MAX2;j++,k++)
arr[k]=b[j];
}
}
else{
arr[k]=b[j];
j++;
if (j==MAX2){
for(;i<MAX1;i++,k++){
arr[k]=a[i];
}
}
}
}
return arr;
}
int main(){
int *a,*b,*c;
printf("Enter elements for first array:\n");
a =create(MAX1);
printf("Enter elements for second array:\n");
b =create(MAX2);
sort(a,MAX1);
sort(b,MAX2);
printf("First array:\n");
display(a, MAX1);
printf("Second array:\n");
display(b, MAX2);
printf("After merging:\n");
c= merge (a,b);
display (c, MAX1 +MAX2);
return 0;
}
This program runs for a while and then stops executing, can anyone tell me the problem? Codeblocks