![]() |
|
#1
|
||||
|
||||
Trinary operatorI was looking at the following function definition and I'm not understanding how it works exactly.
CPP / C++ / C Code:
I tested it out and put 0 and lower values into and got three, fine. But when I put in values greater than zero, like 2, it returned 9. 3 also returned 9. 4 returns 15. |
||||
|
#2
|
|||
|
|||
Re: Trinary operatorQuote:
Function F() as defined above is equivalent to the following: CPP / C++ / C Code:
The sequence generated is: Code:
Otherwise, I do not recognize this sequence as being anything historically notable; it's just a sequence. |
|
#3
|
||||
|
||||
Re: Trinary operatorGreat. Thanks for the help.
|
|
#4
|
||||
|
||||
Re: Trinary operatorHave another question.
I'm trying to write a recursive function that takes one parameter ( an interger ) and returns how many of the digits are 3, recursively. So if the parameter is 31337 the function returns 3, if its 0152, it returns 0. I have the simple parts down, if x = 0 return 0 and if x = 3 return 1, but I can't figure out how to do the part where the function calls itself. Would I need to use an array? Or can it be done without one. |
|
#5
|
|||
|
|||
Re: Trinary operatorQuote:
|
|
#6
|
|||
|
|||
Re: Trinary operatorHere is how I would do it:
CPP / C++ / C Code:
|
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Concept of new operator | vicky_brsh | C++ Forum | 3 | 20-Apr-2008 20:27 |
| Write a C++ program involving operator overloading | jjrsbigo | C++ Forum | 2 | 13-Dec-2006 06:47 |
| infix to postfix | Kacyndra | C++ Forum | 2 | 15-Aug-2005 10:44 |
| C++ PhoneBook | marita | C++ Forum | 46 | 12-Jun-2005 12:10 |
| Operator overloading c++ | clander | C++ Forum | 4 | 25-Apr-2005 09:21 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The