title: Multiplication of two double-digit integer with arrays in Fortran
body: <p>I have tried to write a code for multiplying two double-digit integers like <em>ab * cd</em> using arrays and the preliminary multiplying method. However, when I compile my code and insert any input, the output is a wrong result. I traced my code and I got an appropriate result but in compiling is something different. for example i insert 9 9 9 9 which mean 99 * 99 in this code but the result is 1210 instead of 9801. </p>
  
  <pre><code>program main
      ! multiplication of two double-digit integer ! array method
    implicit none
    integer , parameter :: size=2
    integer , dimension (size)::A
    integer , dimension (size)::B
    integer , dimension (size+1)::C
    integer , dimension (size+2)::D
    integer , dimension (size+2)::E
    integer :: i=0,carry1=0,carry2=0,carry3=0
  
    do i=1,size,1
      read *,A(i)
    end do
    do i=1,size,1
      read *,B(i)
    end do
    do i= 3,2,-1
          C(i)=B(size)*A(i-1)+carry1
          if (C(i)&gt;9)then
              C(i)=mod (C(i),10)
              carry1 = C(i)/10
              else
              carry1=0
          end if
      end do
      C(1)=carry1
  
      D(4)=0
  
      do i=3,2,-1
              D(i)=B(size-1)*A(i-1)+carry2
              if (D(i)&gt;9)then
                  D(i)=mod (D(i),10)
                  carry2= D(i)/10
                  else
                  carry2=0
              end if
      end do
  
    D(1)=carry2
  
    do i=4,2,-1
      E(i)=D(i)+C(i-1)+carry3
      if (E(i)&gt;9) then
          E(i)=mod (E(i),10)
          carry3=1
          else
          carry3=0
      end if
    end do
    E(1)=D(1)+carry3
  
    do i=4,1,-1
      print*,E(i)
    end do
  
  end program main
  </code></pre>