help !!whats the output!!!>??????

F

fegge

#include<stdio.h>
int min(int ,int );

int main(void)
{
int j, k, mimimum;
printf("input two intergers: ");
scanf("%d%d",&j,&k);
mimimum = min(j,k);
printf("\n of the two values %d and %d ,"
"the mimimum is %d.\n\n", j, k, mimimum);
return 0;
}


int mim(int a,int b)
{
if (a < b)
return a;
else
return b;
}
 
S

Sandeep

fegge said:
#include<stdio.h>
int min(int ,int );

int main(void)
{
int j, k, mimimum;
printf("input two intergers: ");
scanf("%d%d",&j,&k);
mimimum = min(j,k);
printf("\n of the two values %d and %d ,"
"the mimimum is %d.\n\n", j, k, mimimum);
return 0;
}


int mim(int a,int b)
{
if (a < b)
return a;
else
return b;
}

output : compiler error
assuming you correct the typo in your function "mim", the function
would still require to handle the case for equal "a" and "b" , but it
would work fine for 2 unequal integers.
 
F

fegge

well,see this:its result on my compiler.


of the two values 12 and 25 ,the mimimum is 2.


oh,why?
 
S

Sandeep

fegge said:
well,see this:its result on my compiler.


of the two values 12 and 25 ,the mimimum is 2.


oh,why?

Your compiler might be broken , it works fine for me.

Also, please include a context to what you are replying.
 
M

Mark McIntyre

assuming you correct the typo in your function "mim", the function
would still require to handle the case for equal "a" and "b" , but it
would work fine for 2 unequal integers.

No, it works fine for a==b too, since if in that case, a is not less
than b, and returning b is a valid response.

The code works by the way, if the OP is seeing different results, he
has different code to this.
Mark McIntyre
 
K

Keith Thompson

fegge said:
#include<stdio.h>
int min(int ,int );

int main(void)
{
int j, k, mimimum;
printf("input two intergers: ");
scanf("%d%d",&j,&k);
mimimum = min(j,k);
printf("\n of the two values %d and %d ,"
"the mimimum is %d.\n\n", j, k, mimimum);
return 0;
}


int mim(int a,int b)
{
if (a < b)
return a;
else
return b;
}

Why are you asking us what the output is? It's your program; compile
and run it yourself.

If you're getting output other than what you expected, you need to
tell us what you expected and what you actually got.

And *please* don't waste our time by posting something that's not the
actual code that you compiled. The stuff you posted won't even
compile (you misspelled "min" as "mim"). We can't possibly guess what
other errors you might have made when you re-typed it. If your actual
program isn't working properly, it's probably because of some other
error you've made.

Post the *exact* code that you actually compiled (don't re-type it,
copy-and-paste it). Show us the output you got and tell us what you
expected.

Finally, read <http://cfaj.freeshell.org/google/> before posting here
again.
 
F

fegge

yes ,you are the most clever boy i have seen. its really my mistake
when writing these codes. i mistake min for *mim*. so whatever i put
into it,the result is 2. i hasnt retyped it .i copied and pasted
them.its the oringinal code. i have asked many ,but you were the only
one who realize whats wrong with it. although i have corrected it
myself, thank you for your post however.
Keith Thompson 写é“:
 
K

Keith Thompson

fegge said:
yes ,you are the most clever boy i have seen. its really my mistake
when writing these codes. i mistake min for *mim*. so whatever i put
into it,the result is 2. i hasnt retyped it .i copied and pasted
them.its the oringinal code. i have asked many ,but you were the only
one who realize whats wrong with it. although i have corrected it
myself, thank you for your post however.

Please don't top-post. See <http://www.caliburn.nl/topposting.html>.

I'm very surprised that your program would have executed at all with
that error; when I tried it, it failed to link.
 
W

William J. Leary Jr.

fegge said:
well,see this:its result on my compiler.

of the two values 12 and 25 ,the mimimum is 2.

oh,why?

Assuming that you observed the two rules of comp.lang.c about code

1. Compiled the code and (if possible) ran it
and
2. Posted the precise code (via cut-and-paste) that you used in "1" above

Then...

because your compiler is using what you meant as a forward reference /
prototype / whatever:

int min(int ,int );

as the actual function, since the later line:

int mim(int a,int b)

doesn't satisfy the forward reference.

It's doing nothing when it's called, and you're getting what ever happens to be
where ever your compiler stores the return value from an integer function. On
many machines that's the primary accumulator of the CPU.

Didn't you get a linker warning? I get:

x.obj(x.c) : error L2029: '_min' : unresolved external

when I try to link this.

What are you using for a compiler/linker? I haven't used anything that would
let me get away with this sort of thing in 25 or 30 years. And even then, I
seem to recall that it choked on the "int, int" part.

When I change "int mim(int a,int b)" to "int min(int a,int b)" I get no
linker errors, and the run-time result is:

input two intergers: 12 25

of the two values 12 and 25 ,the mimimum is 12.

By the way, interesting that you also spelled "minimum" in the output message
starting with "mim".

- Bill
 

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

Forum statistics

Threads
474,176
Messages
2,570,949
Members
47,500
Latest member
ArianneJsb

Latest Threads

Top