Advertisement
bado101

Número primo más cercano

Oct 23rd, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. def numeroPrimo(n1):
  2.     i=1
  3.     div=0
  4.     while(i<=n1):
  5.         if(n1%i==0):
  6.             div=div+1
  7.         i=i+1
  8.     if(div==2):
  9.         return(True)
  10.     else:
  11.         return(False)
  12.  
  13. def primoCercano(n1):
  14.     i=1
  15.     signo=-1
  16.     while(numeroPrimo(n1)==False):
  17.         n1=n1+i
  18.         i=(i+1)*signo
  19.         if(numeroPrimo(n1)):
  20.             return(n1)
  21.  
  22. a=int(input("Ingrese entero"))
  23. print(primoCercano(a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement