K
Keith Thompson
[...]Fred Kleinschmidt said:Presumably your input to this function is a string.
Why do you presume that? The OP specifically referred to the "input
integer".
[...]Fred Kleinschmidt said:Presumably your input to this function is a string.
Malcolm McLean said:Robert Kaplan once wrote a whole book about nothing. It wasn't a joke
or a modern art type book. Nothing is a very interesting subject. For
instance the innovation of zero was condemned by the poet John Donne.
Is a string of no sausages the same thing as no string of sausages?
You can argue forever about that one.
[/QUOTE]Hm, I wasn't aware of that. It sounds a bit odd, actually. Leave it
to Lithp... I appreciate the clarification.
So you can in Python. Well, actually you can return a tuple or the
special built-in value None.
One would have thought that the Beatles would write an album on the roots ofKeith Thompson said:<OT>
It's on my bookshelf, preceded by Eli Maor's book about e, Paul
J. Jahin's book about i (sqrt(-1)), petr beckmann's book about pi, and
the Beatles' album "1".
</OT>
Op Wed, 19 Sep 2007 22:46:10 +0200 schreef jacob navia:
The return type is int, so it returns an int.
Zero in this case is an answer ;-(
I'm making a function that checks the input integer and returns the
value if it is a prime number.
If the integer is not a prime number, then the function should return
nothing.
Problem is, I don't know how to do that.
Isn't there anything like "return null"in C?
Michal Nazarewicz said:Well... i is not really sqrt(-1) since there are two complex numbers
which are not equal to one another which power of two is equal -1 and
i cannot be equal to both numbers.
Keith Thompson said:It's on my bookshelf, preceded by Eli Maor's book about e, Paul
J. Jahin's book about i (sqrt(-1)), petr beckmann's book about pi, and
the Beatles' album "1".
(e-mail address removed) wrote On 09/19/07 13:06,:
No. There's `return NULL;', but that's not
quite what you're after: even `NULL' is "something."
A C function either returns a value of a specified
type, or never returns a value of any kind (such a
function is written as if it "returned" a value of
the type `void').
There are a few avenues open to you. One is to
return either the prime number or some obvious non-
prime like 0 or -1; this is sometimes called "in-band
signaling." Another is to forget about returning the
prime value -- the caller already has a copy, after
all -- and just have the function test for primality
and return true or false. Still another is to have
the function return both the value and a primality
indicator, perhaps in a struct containing both, or
perhaps by "returning" a value via a pointer in the
argument list.
Would you also say that 2 is not really sqrt(4), since there are
two real numbers whose square is 4 and 2 cannot be equal to both
of them?
(You do have a point though: there is no way to distinguish between
i and -i.)
well you have one issue.in stead of returnig nothing,the fonction will
return a value like 0 or -1.
#incldue<stdio.h>
int n;
int prime(int x)
{int r;
if(x%2!=0) r=x;
else r=0;
return r;}
void main()
{
printf("give your number");scanf("%d",&n);
if(prim(n)!=0)
printf("%d",n);}
getch();
I would change the function's interface so that it returns 1 if
the value is prime, 0 otherwise.
Um, -i is the one with the minus sign in front of it.
Seriously, I'm not sure what you mean by "no way to distinguish". For
positive operands, only the positive square root is considered to be
*the* square root (e.g., sqrt(4.0) is 2.0, not -2.0). Similar rules
apply for negative and even complex operands.
[/QUOTE](You do have a point though: there is no way to distinguish between
i and -i.)
Um, -i is the one with the minus sign in front of it.
Seriously, I'm not sure what you mean by "no way to distinguish". For
positive operands, only the positive square root is considered to be
*the* square root (e.g., sqrt(4.0) is 2.0, not -2.0). Similar rules
apply for negative and even complex operands.
I'm making a function that checks the input integer and
returns the value if it is a prime number.
If the integer is not a prime number, then the function should
return nothing.
Problem is, I don't know how to do that.
Isn't there anything like "return null"in C?
C. Benson Manica said:Hm, I wasn't aware of that. It sounds a bit odd, actually. Leave it
to Lithp... I appreciate the clarification.
Coos Haak said:i nor -i is the square root of -1.
What makes you think that?
The same thing I've pointed. In real number domain a square root of
x is defined to be _nonnegative_ number which squared gives x. You
cannot apply analogical definitions to complex numbers since there is no
such think as nonnegative complex number (or nonpositive for that
matter).
[/QUOTE]What makes you think that?
The same thing I've pointed. In real number domain a square root of
x is defined to be _nonnegative_ number which squared gives x.
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.