Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How can we perfom multiplication programatically without using + or * operator.

Reply
Thread Tools

How can we perfom multiplication programatically without using + or * operator.

 
 
mjdeesh_hi@yahoo.co.in
Guest
Posts: n/a
 
      05-29-2006



How can we perfom multiplication programatically without using + or *
operator.
Can any one help out in this one.

Jagadeesh.

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      05-29-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> How can we perfom multiplication programatically without using + or *
> operator.
> Can any one help out in this one.


If you conceptualise the numerical values in a binary format, then left
shifting the value by N is similar to multiplying the value by 2^N.

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      05-29-2006
(E-Mail Removed) said:

> How can we perfom multiplication programatically without using + or *
> operator.


Addition can be done by using ^ (xor), & (and), and << (left shift) in the
proper way.

Multiplication is repeated addition (i.e. addition in a loop).

Alternatively, you can double and halve, if you're careful in the case of an
odd number. Note that doubling will require using addition as described
above (since you are not allowed the * operator).

That's enough of a hint - now do your own homework.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
Ico
Guest
Posts: n/a
 
      05-29-2006
(E-Mail Removed) wrote:
>
> How can we perfom multiplication programatically without using + or *
> operator.
> Can any one help out in this one.
>


#include <stdio.h>

int mult(int a, int b)
{
int c = 0;
while(a--) c -= b;
return -c;
}

int main(void)
{
int a = 5;
int b = 6;

printf("%d x %d = %d\n", a, b, mult(a, b));

return 0;
}

--
:wq
^X^Cy^K^X^C^C^C^C
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      05-29-2006
Ico said:

> (E-Mail Removed) wrote:
>>
>> How can we perfom multiplication programatically without using + or *
>> operator.
>> Can any one help out in this one.
>>

>
> #include <stdio.h>
>
> int mult(int a, int b)
> {
> int c = 0;
> while(a--) c -= b;
> return -c;
> }


Very funny.

But I suspect his teacher is trying to get him to find out how computers do
addition and multiplication "under the hood" (because a computer does not
have the luxury of a magic wand we call '*').

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
newbie
Guest
Posts: n/a
 
      05-29-2006

Richard Heathfield wrote:
> Ico said:
>
> > (E-Mail Removed) wrote:
> >>
> >> How can we perfom multiplication programatically without using + or *
> >> operator.
> >> Can any one help out in this one.
> >>

> >
> > #include <stdio.h>
> >
> > int mult(int a, int b)
> > {
> > int c = 0;
> > while(a--) c -= b;
> > return -c;
> > }

>
> Very funny.
>
> But I suspect his teacher is trying to get him to find out how computers do
> addition and multiplication "under the hood" (because a computer does not
> have the luxury of a magic wand we call '*').
>
> --
> Richard Heathfield
> "Usenet is a strange place" - dmr 29/7/1999
> http://www.cpax.org.uk
> email: rjh at above domain (but drop the www, obviously)


Hehehehehehe!

Totally irrelevent but I thought your magic wand comment was funny

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      05-29-2006
newbie wrote:
> Richard Heathfield wrote:

.... snip ...

> > But I suspect his teacher is trying to get him to find out how computers do
> > addition and multiplication "under the hood" (because a computer does not
> > have the luxury of a magic wand we call '*').

>
> Hehehehehehe!
>
> Totally irrelevent but I thought your magic wand comment was funny


Have you been exposing yourself to nitrous oxide?

 
Reply With Quote
 
Richard Bos
Guest
Posts: n/a
 
      05-29-2006
(E-Mail Removed) wrote:

> How can we perfom multiplication programatically without using + or *
> operator.


#include <stdio.h>

int main(void)
{
double m1=4.0, m2=5.0;

printf("%f times %f equals %f.\n", m1, m2, m1/(1.0/m2));

return 0;
}

HTH; HAND.

Richard
 
Reply With Quote
 
Ico
Guest
Posts: n/a
 
      05-29-2006
Richard Bos <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
>
>> How can we perfom multiplication programatically without using + or *
>> operator.

>
> #include <stdio.h>
>
> int main(void)
> {
> double m1=4.0, m2=5.0;
>
> printf("%f times %f equals %f.\n", m1, m2, m1/(1.0/m2));
>
> return 0;
> }


Taking stupid assignments literally, that must be some kind of dutch
humor

--
:wq
^X^Cy^K^X^C^C^C^C
 
Reply With Quote
 
SM Ryan
Guest
Posts: n/a
 
      05-29-2006
(E-Mail Removed) wrote:
#
#
#
# How can we perfom multiplication programatically without using + or *
# operator.
# Can any one help out in this one.

Any good text on computation theory should include the multiplication
of radix one integers.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Mention something out of a Charleton Heston movie, and suddenly
everybody's a theology scholar.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Source of term "multiplication" in matrix multiplication William Hughes C Programming 13 03-15-2010 02:04 PM
using DataSet programatically without an sql server database Andy B ASP .Net 9 10-22-2008 04:40 AM
howto perfom Image.read Guido Holz Ruby 1 01-31-2008 09:58 PM
install_driver(Oracle) failed: Can't load 'C:/Perl/site/lib/auto/DBD/Oracle/Oracle.dll' for module DBD::Oracle: load_file:The specified procedure could not be found at C:/Perl/lib/DynaLoader.pm line 230. Feyruz Perl Misc 4 10-14-2005 06:47 PM



Advertisments