Help

P

pnreddy1976

Hi friends,
Please find out the problem in followingcode.

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

#define Max(i,j) (i>j)?i:j

int Maximum(int i,intj);

void main()
{
int a,b,c;
a=4;b=5;c=7;
printf("\nMax Value from Maximum
function--->%d",Maximum(a,Maximum(b,c));
printf("\nMax Value from Max Macro-->%d",Maximum(a,Maximum(b,c));
}

int Maximum(int i,intj)
{
if(i>j)
return i;
return j;

}




first state ment giving the exact maximum vale.
But next statement giving wrong.
Please any one tell me where are the wrong??
Thanking you
Reddy
 
K

Kenny McCormack

Hi friends,
Please find out the problem in followingcode.

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

non-standard header
#define Max(i,j) (i>j)?i:j

Not used. Remove.
int Maximum(int i,intj);

syntax error
void main()

non-standard invocation of main()
{
int a,b,c;
a=4;b=5;c=7;
printf("\nMax Value from Maximum
function--->%d",Maximum(a,Maximum(b,c));
printf("\nMax Value from Max Macro-->%d",Maximum(a,Maximum(b,c));
}

int Maximum(int i,intj)

syntax error
 
I

Ian Collins

Hi friends,
Please find out the problem in followingcode.

#include<stdio.h>
#include<conio.h>
What's this header?
#define Max(i,j) (i>j)?i:j
Better to write ((i>j)?i:j), this is probably why it doesn't work.
int Maximum(int i,intj);
Where's the space before j?
void main()

main returns int.
{
int a,b,c;
a=4;b=5;c=7;
printf("\nMax Value from Maximum
function--->%d",Maximum(a,Maximum(b,c));

Missing ')'
printf("\nMax Value from Max Macro-->%d",Maximum(a,Maximum(b,c));

Missing ')' and you don't use the macro!
}

int Maximum(int i,intj)

Where's the space before j?>
first state ment giving the exact maximum vale.
But next statement giving wrong.
Please any one tell me where are the wrong??

If you fix it to compile, it will work.

Please post the code you tested!
 
K

Keith Thompson

Hi friends,
Please find out the problem in followingcode.

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

This is a non-standard header, and you don't even use it.
#define Max(i,j) (i>j)?i:j

In a macro definition, you usually need parentheses around each
parameter and around the entire definition; otherwise you can run into
serious problems with operator precedence.

#define MAX(i, j) ((i) > (j) ? (i) : (j))

Note that I've changed the name from Max to MAX; macros names are
traditionally in all-caps.

The macro can evaluate its arguments more than once, so be careful
about invoking it with an expression that has side effects.

Of course, none of this matters unless you actually use the macro,
which you don't.
int Maximum(int i,intj);

This is a syntax error; it should be "int j", not "intj".
void main()

int main(void)
{
int a,b,c;
a=4;b=5;c=7;
printf("\nMax Value from Maximum
function--->%d",Maximum(a,Maximum(b,c));
printf("\nMax Value from Max Macro-->%d",Maximum(a,Maximum(b,c));
}

int Maximum(int i,intj)
{
if(i>j)
return i;
return j;

}

first state ment giving the exact maximum vale.
But next statement giving wrong.
Please any one tell me where are the wrong??

You couldn't possibly get any output at all from the program you
posted, since it contains syntax error.

If you want to ask us about a program, post the actual program.
Please don't waste our time posting something other than the actual
program. Copy-and-paste; don't re-type, and don't paraphrase.
 
M

Martin Ambuhl

Hi friends,
Please find out the problem in followingcode.
#include<stdio.h>
#include<conio.h>

#define Max(i,j) (i>j)?i:j

int Maximum(int i,intj);

void main()
{
int a,b,c;
a=4;b=5;c=7;
printf("\nMax Value from Maximum
function--->%d",Maximum(a,Maximum(b,c));
printf("\nMax Value from Max Macro-->%d",Maximum(a,Maximum(b,c));
}
int Maximum(int i,intj)
{
if(i>j)
return i;
return j;

}
first state ment giving the exact maximum vale.
But next statement giving wrong.
Please any one tell me where are the wrong??

You went wrong everywhere:

#include<stdio.h>
/* mha: inclusion of non-standard header removed */

/* mha: broken macro fixed; still dangerous since side-effects from
multiple evaluations are possible */
#define MAX(i,j) ((i)>(j)?(i):(j))

int Maximum(int i, int /* mha: missing space inserted */ j);

int /* mha: illiterate 'void' fixed */ main(void)
{
int a = 4, b = 5, c = 7;
/* mha: broken specifier string patched together and end-of-line
character moved to (are you ready?) the end-of-line. Missing right
parenthesis added. */
printf("Max Value from Maximum function--->%d\n",
Maximum(a, Maximum(b, c)));
/* mha: end-of-line character moved to (again) the end-of-line.
Missing right parenthesis added. Fixed illogical use of function
calls when the output string claims a macro is used. */
printf("Max Value from Max Macro-->%d\n", MAX(a, MAX(b, c)));
return 0; /* mha: added return (required for C89;
a good idea for C99) */
}

int Maximum(int i, int /* mha: missing space inserted */ j)
{
if (i > j)
return i;
return j;
}
 
P

pete

Hi friends,
Please find out the problem in followingcode.

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

#define Max(i,j) (i>j)?i:j

int Maximum(int i,intj);

void main()
{
int a,b,c;
a=4;b=5;c=7;
printf("\nMax Value from Maximum
function--->%d",Maximum(a,Maximum(b,c));
printf("\nMax Value from Max Macro-->%d",Maximum(a,Maximum(b,c));
}

int Maximum(int i,intj)
{
if(i>j)
return i;
return j;

}

first state ment giving the exact maximum vale.
But next statement giving wrong.
Please any one tell me where are the wrong??

/* BEGIN new.c */

#include<stdio.h>

#define Max(i, j) ((i) > (j) ? i : (j))

int Maximum(int i, int j);

int main(void)
{
int a, b, c;

a = 4;
b = 5;
c = 7;
printf("Max Value from Maximum function---> %d\n",
Maximum(a, Maximum(b, c)));
printf("Max Value from Max Macro--> %d\n",
Max(a, Max(b, c)));
return 0;
}

int Maximum(int i, int j)
{
if (i > j) {
return i;
}
return j;

}

/* END new.c */
 
A

Andrew Poelstra

Hi friends,
Please find out the problem in followingcode.

How about you tell us the problem? It'd be a lot easier to find.
#include<stdio.h>
#include<conio.h>

Nonstandard header; it's possible we'll be unable to help you.
#define Max(i,j) (i>j)?i:j

Terrible. Space it out more clearly and add parentheses. Also, use
capitals for macros:

#define MAX(i, j) ((i) > (j) ? (i) : (j))

(That's actually less clear, but a /lot/ safer. It still evaluates
the arguments twice, though. Be careful.)
int Maximum(int i,intj);

Syntax error: `intj'. Did you copy and paste this, or type it out?
void main()

Main returns int: int main (void)

Get that right, and I'll look over the rest of the code. Also, copy
and paste. Retyping adds new errors and hides old ones.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,976
Members
47,536
Latest member
MistyLough

Latest Threads

Top