Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This algorithm was crated by Lucas Pereira Torres de Araujo
- #Lista 3 - FUP's Class - 2016.1
- #Item 1.37
- print "Sendo a seguinte sequencia:\nN! / 0! - (N-1)! / 2! + (N-2)! / 4! - (N-3)! / 6! + ... 0! / (2N)!"
- n = input("Digite o valor de N: ")
- soma = float(0)
- for i in xrange(0, n):
- fatn = 1
- for j in xrange(2, n-i):
- fatn = fatn*j
- fatd = 1
- for j in xrange(2, 2*i):
- fatd = fatd*j
- r = fatn/fatd
- r = float(r)
- if i%2 == 1:
- print i+1,"o. - termo =", r
- soma = soma + r
- else:
- print i+1,"o. - termo =", r
- soma = soma - r
- print "Resultado =", soma
Add Comment
Please, Sign In to add comment