# Multiplying Arrays

Page 1 of 1

## 2 Replies - 436 Views - Last Post: 21 July 2011 - 08:51 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=240515&amp;s=3786f233b5556aa40cff126706d100ac&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 bratty_programmer

• New D.I.C Head

Reputation: 0
• Posts: 6
• Joined: 23-June 11

# Multiplying Arrays

Posted 21 July 2011 - 08:22 PM

I am given two arrays with numbers and i have to multiply them both to get the the third array which is the answer. My code is working but for some reason it's not multiplying the numbers correctly. The programme tends to give me the wrong answers for the third array. Maybe someone can take a look at it and guide me on what i am doing wrong please.

bratty_programmer, on 22 July 2011 - 03:19 AM, said:

I am given two arrays with numbers and i have to multiply them both to get the the third array which is the answer. My code is working but for some reason it's not multiplying the numbers correctly. The programme tends to give me the wrong answers for the third array. Maybe someone can take a look at it and guide me on what i am doing wrong please. The code is at the bottom

```#include <stdio.h>
main(){
int array1[6]={4,20,55,24,60,10};
int array2[6]={2,30,10,12,20,33};
int array3[6];
printf("\n\nArray one(1):\t");
for (int i=0;i<6;i++){
printf("%d\t",array1[i]);
}
printf("\n\nArray two(2):\t");
for (int j=0;j<6;j++){
printf("%d\t",array2[j]);
}
printf("\n\n------------------------------------------------------------");
printf("\nResult of multiplying Array1 by Array2:");
printf("\n\nArray three(3):\t");
//for (i=0;i<6;i++);
//for (j=0;j<6;j++);
for(int k=0;k<6;k++){
array3[k]=(array1[i]*array2[j]);
printf("%d\t",array3[k]);
}
}

```

This post has been edited by macosxnerd101: 21 July 2011 - 08:23 PM
Reason for edit:: Please use code tags

Is This A Good Question/Topic? 0

## Replies To: Multiplying Arrays

### #2 buffalobill

Reputation: 21
• Posts: 188
• Joined: 08-July 08

## Re: Multiplying Arrays

Posted 21 July 2011 - 08:32 PM

I think all the arrays need to have k as the index in the product statement.
e.g.
```for(int k=0;k<6;k++)
array3[k]=array1[k]*array2[k];
printf("%d\t",array3[k]);
```

### #3 bratty_programmer

• New D.I.C Head

Reputation: 0
• Posts: 6
• Joined: 23-June 11

## Re: Multiplying Arrays

Posted 21 July 2011 - 08:51 PM

thanks for you tip it worked