Need help on programming (FORTRAN)


Status
Not open for further replies.

trendmatrix

New Member
Jan 17, 2003
123
0
0
49
Visit site
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?

Thanks in advance.

Regards,
TM
 

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
add 1 to x(i)
next j
endfor

else

for j=1 to 886
add 1 to x(i)
next j
endfor

endif

next i
endfor


;)
 

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,
 

How about this?

-----
NUMBER_OF_APPLES=7092
NUMBER_OF_BASKET=8
EACH_BASKET = INTEGER (NUMBER_OF_APPLES/ NUMBER_OF_BASKET)
REMAINDER= MOD (NUMBER_OF_APPLES/ NUMBER_OF_BASKET)

I=0
DO NUMBER_OF_BASKET, 1
I=I+1
BASKET(I)=EACH_BASKET
END DO

I=0
DO REMAINDER, 1
I=I+1
BASKET(I)=BASKET(I)+1
END DO
 

Status
Not open for further replies.