Click here to Skip to main content
16,016,168 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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]);
}
}




but during compilation i got " Expression syntax " ....why??? i can't undrstand ...please help me.....
Posted
Updated 11-Aug-22 7:03am
v2

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

C#
// 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;
}
 
Share this answer
 
v2
Looks like a homework assignment...

1. What is:
C#
#include
#include



2. Have you heard about indentation?

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

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

into
C++
merge(x,y,p,q);


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


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

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


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


7. Same with
C++
while(i<p)>


and

while(j<q)>
C++



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
C++
void
.
 
Share this answer
 
v3
Comments
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
Michael Haephrati 20-Feb-13 15:34pm    
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" ???
Michael Haephrati 20-Feb-13 15:36pm    
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900