Debug this error if anybody can plz!!!!

Status
Not open for further replies.

ashwini jayaraman

Member level 2
Joined
Jan 17, 2013
Messages
49
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,601

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<stdio.h>
#include<conio.h>
void merge(int a[100],int b[100],int *m,int *n);
void sort(int c[100],int *m,int *n);
void main()
{
    int a[100],b[100],i,n,m,k;
    clrscr();
    printf("\n Enter no of elements: ");
    scanf("\t%d",&n);
    printf("\n Enter no of elements in 2nd array: ");
    scanf("\t%d",&m);
    for(i=0;i<n;i++)
    {
    scanf("\t%d",&a[i]);
    }
    printf("\n");
    for(k=m+n-1;k>=n;k--)
    {
    scanf("\t%d",&b[k]);
    }
 
    merge(a,b,&m,&n);
 
getch();
}
void merge(int a[],int b[],int *m,int *n)
{
       int c[100];
       int i,j,k;
    for(i=0;i< *n;i++)
    {
    c[i]=a[i];
    }
    for(j=(*m + *n)-1;j >= *n;j--)
    {
    c[j]=b[j];
    }
    printf("\n");
    for(k=0;k< *m + *n;k++)
    {
    printf("\t%d",c[k]);
    }
    sort(c,&m,&n);
}
void sort(int c[],int *m,int *n)
{
for(int i=0;i<(*m + *n)-1;i++)
{
if(c[i]>c[i+1])
{
int temp=c[i+1];
int temp1=c[i];
c[i+1]=temp1;
c[i]=temp;
}
}
for(int i=0;i<*m + *n;i++)
{
printf("\t%d",c[i]);
}
}



This is a code for merging & sorting using functions (call by reference).Couldn't find what's wrong in this code !!!

Somebody, please identify the bug!!!

Thanks.
 
Last edited by a moderator:

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…