MHB Explore the Manipulated Contents of an Array with Multiplication and Addition

  • Thread starter Thread starter Henry R
  • Start date Start date
  • Tags Tags
    Array
AI Thread Summary
The discussion focuses on determining the contents of an integer array after a series of mathematical manipulations. Initially, arr[0] is set to 2, leading to arr[1] being calculated as 3. Subsequent calculations yield arr[2] as 6, arr[3] as 1 (taking the integer part of 1.5), and arr[4] as 1. The participants clarify the importance of integer division in the context of arrays. The final contents of the array are confirmed as [2, 3, 6, 1, 1].
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: 84
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: 83
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.
 
Back
Top