## Help on Consecutive numbers

## Help on Consecutive numbers

(OP)

Hi,

I am very new to programming using FORTRAN. Please, you guys should help me out in the problem I will describe below:

I want to write a FORTRAN program that arranges the numbers in consecutive pairs. That is AABBAABBAABB, etc. Where A is positive and B is negative but both A and B are of the same magnitude. The program should be that should the number following immediately is not of the same sign that it changes the sign to be the same such that they occur in pairs as I showed below.

Thank you very much for your help.

I am very new to programming using FORTRAN. Please, you guys should help me out in the problem I will describe below:

I want to write a FORTRAN program that arranges the numbers in consecutive pairs. That is AABBAABBAABB, etc. Where A is positive and B is negative but both A and B are of the same magnitude. The program should be that should the number following immediately is not of the same sign that it changes the sign to be the same such that they occur in pairs as I showed below.

Thank you very much for your help.

## RE: Help on Consecutive numbers

...even then we still will not help, around here, we do not write programs from scratch...YOU need to write the program, show that you are putting your own effort in trying to learn Fortran and THEN, if it gets tricky, we can help.

## RE: Help on Consecutive numbers

In essence no element should occur in singles.

Thanks for your assistance.

program AABB

! the program generate fibonacci numbers

! f(0) = 0

! f(1) = 1

! f(n) = f(n-1) + f(n-2) for n>1

implicit none

integer :: i, jc,iseed

real:: V0,V(20),Vt

V0 = 2

iseed=88901

do i=1,20

V(i)=V0*sign(1.0,ran(iseed)-0.5)

end do

i=0

do jc=1,20

if(i) then

Vt = -V(jc)

end if

i=i+1

if(i.and.Vt.eq.-V(jc)) then

Vt = -V(jc)

else !if(i.eq.i.and.Vt.eq.V(jc)) then

Vt = V(jc)

end if

write (*,102) jc, i,V(jc)

end do

102 format(i3, i12, f9.4)

stop

end

## RE: Help on Consecutive numbers

## CODE

## CODE

Instead, you need to do something line (i > 0) if that is what you meant or possibly use the mod() function if you would like to test for odd/even i...

## RE: Help on Consecutive numbers

Thanks for your explanations. I am using the "i" as a counter which should be increased by 1 each time. Then, I wan to check if the initial "i" and the "i+1" have the same sign. If not, I want to make them the same so that the sign occur in pairs as I explained before.

## RE: Help on Consecutive numbers

## CODE

## RE: Help on Consecutive numbers

## RE: Help on Consecutive numbers

## RE: Help on Consecutive numbers

Here is this working version, as far as I can tell

## CODE

## RE: Help on Consecutive numbers

## RE: Help on Consecutive numbers

Best.