0% found this document useful (0 votes)
33 views3 pages

Multiplication Without Multiplication Operator in Matlab

Elaborate code on an utterly foolish assignment of multiplying 2 fractional numbers in Matlab without using the * operator.

Uploaded by

RVCJ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

Multiplication Without Multiplication Operator in Matlab

Elaborate code on an utterly foolish assignment of multiplying 2 fractional numbers in Matlab without using the * operator.

Uploaded by

RVCJ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PROBLEM-2:

Perform the multiplication of 37.58 and 82.29 without using multiplication operator.

You can use loops and addition

a=37.58; %% Input Number 1


b=82.29; %% Input Number 2

i=0;
j=0;
c=a;
d=b;
while c>1
c=c-1;
i=i+1;
end
while d>1
d=d-1;
j=j+1;
end
c %% Decimal Part of Input Number 1 ( f1 )

c = 0.5800

d %% Decimal Part of Input Number 2 ( f2 )

d = 0.2900

i %% Integer Part of Input Number 1 ( i1 )

i = 37

j %% Integer Part of Input Number 2 ( i2 )

j = 82

f=0;
y=0;
for e=1:100
f=f+d;
y=y+c;
end
y %% Integer form of Decimal Part of Input Number 1

y = 58.0000

f %% Integer form of Decimal Part of Input Number 2

f = 29.0000

p1=0;
for p2=1:y+1
p1=f+p1;

1
end
p1; %% Integer form of the product of Decimal Parts of Input Numbers 1 & 2

h=0;
for g=1:i
h=h+j;
end
k=0;
for l=1:i
k=k+d;
end
m=0;
for n=1:j
m=m+c;
end
h %% Product of Integer Parts of Input Numbers 1 & 2

h = 3034

k %% Product of Integer Part of Input Number 1 & Decimal Part of Input Number 2

k = 10.7300

m %% Product of Integer Part of Input Number 2 & Decimal Part of Input Number 1

m = 47.5600

q=0.0001; %% Minimum value in the scale of the decimal product


x1=1; %% Flag Variable for indexing product arrays
while q<=1 %%
x=0; %%
for v=1:1000000 %%
x=x+q; %% Integer form of the different possible products
end %%
br(x1)=q; %%
q=q+0.0001; %% Incrementing counter value
ar(x1)=x; %%
x1=x1+1; %% Incrementing index
end
e1=br(int64(p1)) %% Product of Decimal Parts of Input Numbers 1 & 2

e1 = 0.1682

This program only allows real numbers with 2 decimal places to be multiplied.

To multiply 2 numbers with 3 places of of decimal more, this section of the code needs to be modified. But that
will take significantly more time to compute since the number of iterations will increase 1000 fold.

Final_Product=h+k+m+e1

Final_Product = 3.0925e+03

Product_Using_Multiplication_Operator=a*b %% Step 1 for Validation

2
Product_Using_Multiplication_Operator = 3.0925e+03

Variation=Final_Product-Product_Using_Multiplication_Operator %% Step 2 for Validation

Variation = 0

You might also like