Need help on programming (FORTRAN)


Status
Not open for further replies.
Jan 17, 2003
123
0
0
43
Visit site
#1
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
 

Marx

New Member
Apr 2, 2003
379
0
0
East
Visit site
#2
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


;)
 

Pinoy

New Member
Jan 17, 2002
1,702
1
0
ClubSNAP East
www.flickr.com
#3
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
Jan 19, 2002
1,166
0
36
Singapore
#4
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.
Top Bottom