1. How to update value

How to update array value in program

Code:
```#include <stdio.h>
int main ()
{
int i, input;

int array[5] = { 10, 20, 30, 40, 50 };
printf ("Enter input\n");
scanf ("%d", &input);

if (input > 0 && input < 5)
// array value depend on input
// input is 1 then 10 become 5
// update array =  5, 20, 30, 40, 50
// input is 3 then 30 become 15
// update array =  5, 20, 15, 40, 50

return 0

}```

2. So have you figured out the relationship between 10 and 5, or between 30 and 15 ?

What about the relationship between the number you input (say 3), and the subscript for the value you intend to modify?

3. Originally Posted by Salem
So have you figured out the relationship between 10 and 5, or between 30 and 15 ?

What about the relationship between the number you input (say 3), and the subscript for the value you intend to modify?
new value is half of original value

first list 10, 20, 30, 40, 50
say input is 1

first list 5, 20, 30, 40, 50

say input is 4
first list 5, 20, 30, 20, 50

I don't understand how to update new value in array ?

4. You mean you've never assigned a value to an array element before?

array[i] = array[i] + 1;

Now do what you want to do.

5. Originally Posted by Salem
You mean you've never assigned a value to an array element before?

.

five integer stored into array

int array[5] = { 10, 20, 30, 40, 50 }

Ask the user which value they want to half
input number 1 to 5

let say input is 2 : 20

print the array with new value

int array[5] = { 10, 10, 30, 40, 50 }

where 10 is half value of 20