473,830 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20531

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.programmin g, 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.programmin g, 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.programmin g. 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.o rg/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
2395
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 people have observed this fact too, and why? Below is the code I used, with output from my machine. python bench.py running 1000 iterations of matrix multiply of row 1000-vector
2
3099
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 on I will try to multiply these values. When I have found the parent I will multiply with its parent and so on, all the way to the top of the xml-file. The files are pasted below. First I have tried to find these values, the next step will be...
15
13289
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 matricies at compile-time? Any help would be appreciated. Hopefully this code comes in useful for someone, let me know if you find it useful, or if you have suggestions on how to improve it. // Public Domain by Christopher Diggins, 2005 ...
4
7249
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
2538
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 database I get the result, but I want to do it in the code.
0
4003
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 see my page thru Firefox, everything is okay but when I see it with IE, there are distorted things and some pictures don't show up. My platform is Windows XP home edition. Here's my css code to the site /************* Spiderman 3...
12
2108
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 with the following: Can this create any problems with GNU g++ compilation, linking etc? What would be the impact to the performance of the system? Anything else we have to consider?
14
5176
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 answer will fit in a 64-bit integer. Let me simplify it by using unsigned chars (8 bits):
1
1995
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: /usr/local/lib/perl5/site_perl/5.6.2/sun4-sunos/auto/Tk/Event/Event.a(Event.o): _LangExit: multiply defined ld: /usr/local/lib/perl5/site_perl/5.6.2/sun4-sunos/auto/Tk/Event/Event.a(Event.o): _Tcl_Free: multiply defined ld:...
0
9793
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10526
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10206
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6951
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.