# Need help on programming (FORTRAN)

Status
Not open for further replies.

#### trendmatrix

##### New Member
Hi,

Let's say I have 7092 apples and I want to separate the 7092 apples evenly to 8 baskets. Unfortunately, 7092/8 is 886.5 which is not possible. Hence the next best way (first scenario) is to give 886 apples to the first 7 baskets each, and the last one to have 890 apples.

However, this is still not the best way to separately the apples evenly. An even better way (second scenario) would be to give the first 4 baskets 887 apples, and the last 4 baskets to have 886 apples each.

So how will the pseudo-code look like for the second scenario?

Regards,
TM

#### Marx

##### New Member
a simple logic will look like this: (uncompiled, simulated)

dim x(8);

for i=1 to 8

if i<5

for j=1 to 887
next j
endfor

else

for j=1 to 886
next j
endfor

endif

next i
endfor

#### Pinoy

##### New Member
Do an integer division or modulo. I know nuts about FORTRAN but in Java, for example, you can have something like:

7 % 2 = 1; // remainder is returned

So logic-wise, you can check if the remainder ain't zero, and if so, you can assign more to the other / last basket.

HTH,

:Later,

#### rty

##### Senior Member

-----
NUMBER_OF_APPLES=7092

I=0