Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

holaaaa

program main
integer:: i,j
integer:: creciente 
integer:: n
logical::esPrimo
integer, allocatable :: U(:)


write(*,*) 'Escribe un numero'
read(*,*) n
   

    do i=2,n !hasta n ya que me dice los primos menores que n
             
         j=0
        creciente=2
        esPrimo=.true.

      do while((esPrimo) .AND. (creciente < i))

            if (mod(i,creciente)==0) then
                esPrimo=.false.
            else
                creciente=creciente+1
            end if 

        end do
        if ((esPrimo).eqv.(.true.))then !si la condicion de esprimo sigue siendo verdadero, imprime q ese numero es primo
            j=j+1
            write(*,*) i, 'es primo' 
            
        end if 
    end do

allocate (U(j))


 do i=2,n 
        j=0
        creciente=2
        esPrimo=.true.

      do while((esPrimo) .AND. (creciente < i))

            if (mod(i,creciente)==0) then
                esPrimo=.false.
            else
                creciente=creciente+1
            end if 

        end do
        if ((esPrimo).eqv.(.true.))then 
        j=j+1
        U(j)=i
        end if
            esPrimo=.true. 
end do 

write(*,*) U

deallocate (U)

         
end program main

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.