Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,398 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,117 people online right now. Registration is fast and FREE... Join Now!




Multiplying with out "*" and LOOPS

 
Reply to this topicStart new topic

Multiplying with out "*" and LOOPS

jabez_jb
31 Aug, 2006 - 03:45 AM
Post #1

New D.I.C Head
*

Joined: 18 Aug, 2006
Posts: 10


My Contributions
Rewrite the following function so that the following conditions are satisfied:
a. The multiplication operator ('*') is not used.
b. The division operator ('/') is not used.
c. The function does not make use of loops.

CODE

int MultiplyBy321(int value)
{
int rslt;
rslt = value * 321;
return rslt;
}

USING C++
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: Multiplying With Out "*" And LOOPS
31 Aug, 2006 - 03:55 AM
Post #2

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
Hmm is this an assignment or you're posting this for fun?
User is offlineProfile CardPM
+Quote Post

jabez_jb
RE: Multiplying With Out "*" And LOOPS
31 Aug, 2006 - 03:56 AM
Post #3

New D.I.C Head
*

Joined: 18 Aug, 2006
Posts: 10


My Contributions
no problem....i got the answer......but dunno the way is correct or not

CODE

int MultiplyBy321( int val )
{
  if( val == 1 )

  return 321;
  
   else
    return ( (MultiplyBy321(val-1)) +( 321));
}

User is offlineProfile CardPM
+Quote Post

frog
RE: Multiplying With Out "*" And LOOPS
31 Aug, 2006 - 05:05 AM
Post #4

unleashed
Group Icon

Joined: 26 Mar, 2006
Posts: 682


Dream Kudos: 500
My Contributions
that works fine. i like thee ques though
User is offlineProfile CardPM
+Quote Post

born2c0de
RE: Multiplying With Out "*" And LOOPS
31 Aug, 2006 - 05:27 AM
Post #5

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,935



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
I think this Code better fits the bill.

This function can be used to multiply any number (since you can pass it as a parameter instead of hardcoding it) and has a sort of a cool-factor to it.
tongue.gif
User is offlineProfile CardPM
+Quote Post

violent_crimson
RE: Multiplying With Out "*" And LOOPS
2 Sep, 2006 - 05:13 AM
Post #6

New D.I.C Head
*

Joined: 31 Aug, 2006
Posts: 36


My Contributions
CODE

int MultiplyBy321( int val )
{
if( val == 1 )

return 321;

else
return ( (MultiplyBy321(val-1)) +( 321));
}


the function working because it returns itself is remarkable... great job you weird thinker O_o
User is offlineProfile CardPM
+Quote Post

Dark_Nexus
RE: Multiplying With Out "*" And LOOPS
2 Sep, 2006 - 10:21 AM
Post #7

or something bad...real bad.
Group Icon

Joined: 2 May, 2004
Posts: 1,309



Thanked: 3 times
Dream Kudos: 625
My Contributions
it's called "recursion"
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:00AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month