473,385 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

multiply two arrays

Hi. I've a homework including calculations with arrays. I've stuck on
multiply them. Can you help me?

Feb 22 '06 #1
8 20501

l.j. wrote:
Hi. I've a homework including calculations with arrays. I've stuck on
multiply them. Can you help me?


Quite likely, but pray tell what the actual problem is.

If it's not in C, you're better of in comp.programming, or a group
dedicated to the language you're using.

If you expect us to do your homework, that can be arranged as well. For
a fee, and after you give us your teacher's details so we can send her
the solution directly.

--
BR, Vladimir

Feb 22 '06 #2
It is in c,we just start to learn it. I don't expect you to do my
homework, I'm working on it for days, I managed to do add up and
substraction. But I couldn't do multiplication. I just asked for help.
Vladimir S. Oka wrote:
l.j. wrote:
Hi. I've a homework including calculations with arrays. I've stuck on
multiply them. Can you help me?


Quite likely, but pray tell what the actual problem is.

If it's not in C, you're better of in comp.programming, or a group
dedicated to the language you're using.

If you expect us to do your homework, that can be arranged as well. For
a fee, and after you give us your teacher's details so we can send her
the solution directly.

--
BR, Vladimir


Feb 22 '06 #3
"l.j." writes:
Hi. I've a homework including calculations with arrays. I've stuck on
multiply them. Can you help me?


Well, this works in the simplest case. Does that help any?

c[i] = a[i] * b[i];
Feb 22 '06 #4
l.j. wrote:
It is in c,we just start to learn it. I don't expect you to do my
homework, I'm working on it for days, I managed to do add up and
substraction. But I couldn't do multiplication. I just asked for help.


Please don't top-post.

I did offer to help, but you still refuse to say what your problem is?

<OT>
Do you need scalar or vector multiplication?

V1 = [a1, a2, ...], V2 = [b1, b2, ...]

Scalar (I'll use `*` for this): V1*V2 = a1*b1 + a2*b2 + ...

Vector (I'll use `x`): V1*V2 = [a1*b1, a2*b2, ...]
</OT>

Now, try to write this in C, and let us know if you have problems.

--
BR, Vladimir

Feb 22 '06 #5
l.j. schrieb:
Hi. I've a homework including calculations with arrays. I've stuck on
multiply them. Can you help me?


Elementwise, inner, dyadic, ... product?
Give us code which can be compiled and exhibits your exact
problem. State clearly and concisely what your problem is
at this point.
If you know that your problem is a problem with data structures
or algorithms, ask in comp.programming. Once more: State your
problem clearly and concisely.

Maybe this helps:
<http://www.catb.org/~esr/faqs/smart-questions.html>
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Feb 22 '06 #6
I want a result like this:
(5,6)*(5,2) = (2,9,1,2)
but I get this: (2,6,2)
I'm using net.2005 and my code is:
#include <stdio.h>
#define n 2
int main(){
int A[n]={5, 6},
B[n]={5, 2},
C[n+1];
int carry=0;
int i;

for(i=n-1;i>=0;i--){
C[i+1]=( carry+A[i]*B[i] )%10;

carry=(int)(( carry+A[i]*B[i] )/10);
}
C[0]=carry;
printf(" ");
for(i=0;i<n;i++)
printf("%d ",A[i]);
printf("\n ");

for(i=0;i<n;i++)
printf("%d ",B[i]);
printf("\n");
for(i=0;i<=n;i++)
printf("%d ",C[i]);
printf("\n");

return 0;
}
I think I need to use another loop but where and how?
osmium wrote:

Well, this works in the simplest case. Does that help any?

c[i] = a[i] * b[i];


Feb 24 '06 #7
On Fri, 24 Feb 2006 05:41:48 -0800, l.j. wrote:
I want a result like this:
(5,6)*(5,2) = (2,9,1,2)
but I get this: (2,6,2) <code snipped> I think I need to use another loop but where and how?


I don't want to solve this for you, but you are right. You need another
loop. Digit by digit multiplication involves multiplying the *whole* of
one array, by *each* digit of the other in turn. The results can be
accumulated into an array as you go provided you remember to add the
digits in the right position: i.e. when multiplying by the second digit
of A you add into the second (and higher) digits of C.

Note: you have declared C of size n+1 (3) but you are clearly ware that
{5,6} * {5,2} has four digits.

--
Ben.

Feb 24 '06 #8
l.j. wrote:
I want a result like this:
(5,6)*(5,2) = (2,9,1,2)
but I get this: (2,6,2)
I'm using net.2005 and my code is:

#include <stdio.h>
#define n 2

int main(){
int A[n]={5, 6},
B[n]={5, 2},
C[n+1];


The C array has enough space for three elements.
There's no way it's going to be something like
(2,9,1,2)

<snip>

Oh! Just noticed this was a top post.
Please don't top post:
see <http://ursine.dyndns.org/wiki/index.php/Top_Posting>

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Feb 24 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Zhang Le | last post by:
Hi, I did a small benchmark of matrix-vector multiply operation using Numeric module. I'm a bit suprised to find matrix*col-vector is much faster than row-vector*matrix. I wonder whether other...
2
by: Martin Pettersson | last post by:
Hi all, I'm trying to multiply parent values in xsl. The thing is that I start with a value down in the xml-structure. From that value (in my case 'qty' value) I check the parent value and later...
15
by: christopher diggins | last post by:
Here is some code I wrote for Matrix multiplication for arbitrary dimensionality known at compile-time. I am curious how practical it is. For instance, is it common to know the dimensionality of...
4
by: trint | last post by:
Why do we have to use decimal.multiply to multiply two intgers? I just want to multiply these two values: int oneThousand = 1000; int watCHTimer1 = value from a textbox; Thanks, Trint
11
by: vips | last post by:
I have a string str="10*12*14" now I want the total of this value i.e. 10 multiply 12 multiply 14 how do i get it ? is there any function in vb.net to do that ?? if i put it as query to...
0
by: komandjaja | last post by:
Hi everybody. I am new here and I don't know much about CSS. However, I have a blog at multiply http://komandjaja.multiply.com and I have customized the CSS codes there to make a new theme. When I...
12
by: Janaka Perera | last post by:
Hi All, We have done a object oriented design for a system which will create a class multiply inherited by around 1000 small and medium sized classes. I would be greatful if you can help me...
14
by: Default User | last post by:
Hi, If I have three 64 bit integers and I want to do this operation on them: x*y/z Lets say that what we are multiplying by (y) is offset by what we are dividing by (z) so that the final...
1
by: Gavin Chen | last post by:
Hello: I tried to install Tk800.015 on SunOS 4.1.4 with perl 5.6.2. At "make test" time, I got the error message as below: collect2: ld returned 2 exit status ld:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.