12,954,856 members (63,071 online)
Rate this:
See more:
i got a code :

```#include <stdio.h>
#include <conio.h>
void main()
{
int i,j,p,q,x[50],y[50];
void merge(int x[],int y[],int p,int q);
printf("Enter the length of the 1st sorted array :");
scanf("%d",&p);
printf("Enter the sorted values of the 1st array :");
for(i=0;i<=p;i++)
scanf("%d",&x[i]);
printf("Enter the sorted values of the 2nd array :");
scanf("%d",&q);
printf("Enter the sorted values of the 2nd array :");
for(j=0;j<=q;j++)
scanf("%d",&y[j]);
merge(x[],y[],p,q);
getch();  }
void merge(int x[],int y[],int p,int q)
{
int i=0,j=0,k=0,z[100];
while(i<p mode="hold" />{
if(x[i]<y[j])>
{
z[k]=x[i];
i++;
k++;
}
else if(x[i]>y[j])
{
z[k]=y[j];
j++;
k++;
}
else
{
z[k]=x[i];
i++;
j++;
k++;
}
}while(i<p)>
{
z[k]=x[i];
i++;
k++;
}
while(j<q)>
{
z[k]=y[j];
j++;
k++;
}
printf("The new merged array is :");
for(i=0;i<k;i++)>
{
printf("%d",z[i]);
}
}
```

Posted 20-Feb-13 9:10am
Updated 20-Feb-13 9:16am
v2

Rate this:

## Solution 2

If you create a Console application using Visual Studio C++ 2010, you should get something like that:

```// Test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <conio.h>

int _tmain(int argc, _TCHAR* argv[])
{
int i,j,p,q,x[50],y[50];
void merge(int x[],int y[],int p,int q);
printf("Enter the length of the 1st sorted array :");
scanf("%d",&p);
printf("Enter the sorted values of the 1st array :");
for(i=0;i<=p;i++)
scanf("%d",&x[i]);
printf("Enter the sorted values of the 2nd array :");
scanf("%d",&q);
printf("Enter the sorted values of the 2nd array :");
for(j=0;j<=q;j++) scanf("%d",&y[j]);
merge(x,y,p,q);
getch();
}
void merge(int x[],int y[],int p,int q)
{
int i=0,j=0,k=0,z[100];
while(i)
{
if(x[i]<y[j])
{
z[k]=x[i];
i++;
k++;
}
else if(x[i]>y[j])
{
z[k]=y[j];
j++;
k++;
}
else
{
z[k]=x[i];
i++;
j++;
k++;
}
}
while(i<p)
{
z[k]=x[i];
i++;
k++;
}
while(j<q)
{
z[k]=y[j];
j++;
k++;
}
printf("The new merged array is :");
for(i=0;i<k;i++)
{
printf("%d",z[i]);
}
return;
}```
v2
Rate this:

## Solution 1

Looks like a homework assignment...

1. What is:
```#include
#include```

2. Have you heard about indentation?

3. First, lets take care of the required header files.

4. Change this line
`merge(x[],y[],p,q);`

into
`merge(x,y,p,q);`

5. Change
`<pre lang="c++">`
while(i
into
`while(i)`

(I TOLD YOU TO INDENT YOUR CODE !!!!)

6. What is this line?
`if(x[i]<y[j])>`

Change it to
`if(x[i]<y[j])`

7. Same with
`while(i<p)>`

and

while(j<q)>

and also
`for(i=0;i<k;i++)>`

8. Change return 0; into return; as merge is not defined to return anything. It is defined as
`void`
.
v3
Sergey Alexandrovich Kryukov 20-Feb-13 15:21pm

Stop posting non-answers! You have a good change to loose your CodeProject account for a lot of abuse. Some more abuse reports and you are done. Please, remove all "answers" if they are not solutions.
—SA

Sergey, do you see any comments posted as answers? If so, please let me know. I have published this answer here (which was accepted) too early...
Sergey Alexandrovich Kryukov 20-Feb-13 19:03pm

I re-voted with a 5, taking into account your update.
And thank you for your note. If you improve some down-voted answer, please never hesitate to send a note. Mistakes and accidents happen, we all understand that...
I did not mean just comments posted as answers. Please review your answers by yourself (but when I get some more time, I'll try to send you my comments on what I think was inappropriate...)
—SA
wikiabhishek 20-Feb-13 15:25pm

yaaa this is a homework assignmnt....nw will u plzz clear me the compilation error "Expression Syntax" ???

I don't know if codeproject is for homework assignments but I hope I helped you.Please note that my solution fixes only the compilation errors (and structure the code more decently), you still have to check the logic of your program. If you have any further questions, please let me know.
wikiabhishek 20-Feb-13 16:19pm

thnx...i got my solution

You are welcome!

Top Experts
Last 24hrsThis month
 OriginalGriff 130 Kornfeld Eliyahu Peter 100 Dave Kreskowiak 68 CHill60 60 RickZeeland 55
 OriginalGriff 6,559 CHill60 3,550 Maciej Los 3,153 ppolymorphe 2,030 Jochen Arndt 1,975