Explore the Manipulated Contents of an Array with Multiplication and Addition

  • Context: MHB 
  • Thread starter Thread starter Henry R
  • Start date Start date
  • Tags Tags
    Array
Click For Summary

Discussion Overview

The discussion revolves around the manipulation of an integer array in a programming context, specifically focusing on how to determine the contents of the array after a series of operations involving addition, multiplication, and division. Participants are attempting to solve the problem and clarify their understanding of the operations applied to the array elements.

Discussion Character

  • Homework-related
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • Some participants assert that the initial value of arr[0] is 2, leading to arr[1] being calculated as 3 through addition.
  • Others propose that the subsequent values of the array can be derived step-by-step, with specific calculations for arr[2], arr[3], and arr[4] based on previous results.
  • There is a contention regarding the interpretation of the division operation, particularly how integer division affects the result for arr[3].
  • Some participants express confusion over the calculations and seek clarification on the results presented by others.
  • A later reply emphasizes the importance of considering the integer nature of the array when performing division, noting that 1.5 is treated as 1 in this context.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the final contents of the array, as there are differing interpretations and calculations presented throughout the discussion.

Contextual Notes

Participants express uncertainty about specific steps in the calculations and the implications of integer division, indicating that assumptions about how operations are performed may vary.

Henry R
Messages
25
Reaction score
0
Please identify the contents of the array after the following manipulations.

int arr[5];

arr[0] = 2;
arr[1] = arr[0] + 1;
arr[2] = arr[0] * arr[1];
arr[3] = arr[1] / arr[0];
arr[4] = arr[3] * arr[3];

View attachment 3674

*Involves multiplication, addition from the array. Solve it...
 

Attachments

  • array.PNG
    array.PNG
    555 bytes · Views: 105
Technology news on Phys.org
Henry R said:
Please identify the contents of the array after the following manipulations.

int arr[5];

arr[0] = 2;
arr[1] = arr[0] + 1;
arr[2] = arr[0] * arr[1];
arr[3] = arr[1] / arr[0];
arr[4] = arr[3] * arr[3];

View attachment 3674

*Involves multiplication, addition from the array. Solve it...

This is easy.. At the beginning there is the command [m]arr[0]=2;[/m], then you just have to replace the value that [m]arr[0][/m] got at the second expression.
So you will have arr[1]=2+1=3.
In the same way you can find the other contents of the array (Whew)
 
evinda said:
This is easy.. At the beginning there is the command [m]arr[0]=2;[/m], then you just have to replace the value that [m]arr[0][/m] got at the second expression.
So you will have arr[1]=2+1=3.
In the same way you can find the other contents of the array (Whew)

This is my effort. Just got confuse.

View attachment 3675
 

Attachments

  • array.PNG
    array.PNG
    1.2 KB · Views: 111
Henry R said:
This is my effort. Just got confuse.

https://www.physicsforums.com/attachments/3675

It isn't like that... (Shake) How did you find these results?
 
evinda said:
It isn't like that... (Shake) How did you find these results?

no, idea. But, I think the second expression is correct according to your explanation.
 
Henry R said:
no, idea. But, I think the second expression is correct according to your explanation.

It should be like that:

[m]arr[1]=2+1=3
arr[2]=2*3=6
arr[3]=3/2=1
arr[4]=1*1=1[/m]

Do you understand why? (Thinking)
 
evinda said:
It should be like that:

[m]arr[1]=2+1=3
arr[2]=2*3=6
arr[3]=3/2=1
arr[4]=1*1=1[/m]

Do you understand why? (Thinking)

arr[0] = 2
arr[1] = 3

expression 3...
arr[2] = arr[0] * arr[1] =6, is because 2 * 3 = 6.
 
Henry R said:
arr[0] = 2
arr[1] = 3

expression 3...
arr[2] = arr[0] * arr[1] =6, is because 2 * 3 = 6.

[m] arr[3]=arr[1]/arr[0]=3/2=1[/m]
We take the integer part of the number $1.5$ since [m]arr[/m] is an array of integers. (Nerd)
 
evinda said:
[m] arr[3]=arr[1]/arr[0]=3/2=1[/m]
We take the integer part of the number $1.5$ since [m]arr[/m] is an array of integers. (Nerd)

Oh, Thank you so much for reminds me that. Yeah! It's array treat 1.5 as integer.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
4K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
3
Views
2K