Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C
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 20-Feb-13 9:10am
Edited 20-Feb-13 9:16am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

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;
}
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

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
.
  Permalink  
v3
Comments
Sergey Alexandrovich Kryukov at 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 at 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 at 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 at 20-Feb-13 16:19pm
   
thnx...i got my solution
   
You are welcome!

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

  Print Answers RSS
0 OriginalGriff 404
1 Nirav Prabtani 268
2 _Amy 230
3 CHill60 170
4 Sergey Alexandrovich Kryukov 166
0 OriginalGriff 8,004
1 Sergey Alexandrovich Kryukov 7,017
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100