New Question!!!
WAP in python/java to print this following series :
I) 23 21 24 19 26 15 28 11 30 7 36...nth term
ii) 4 12 84 3612...nth term
_
Also, write the logic of this series
Answers
Answered by
0
Explanation:
I) 23 21 24 19 26 15 28 11 30 7 36...nth term the answer is 5
ii) 4 12 84 3612...nth term the answer is 6526884
Answered by
4
Answer:
Here comes the Python program for this question.
Question 1:
Series: 23 21 24 19 26 15 28 11 30 7 36...N terms
C∅de:
def nextPrime(n):
x=n+1
while True:
c=sum([1 for i in range(1,x+1) if x%i==0])
if c==2:
return x
x+=1
n,a,b,c=int(input("Enter limit - ")),23,2,-1
for i in range(n):
print(a, end=" ")
a,b,c=a+(b*c),nextPrime(b),-c
Algorithm:
- START.
- Accept the limit from the user,say n.
- Initialise a= 23, b = 2, c = -1
- Iterate a loop n times.
- Display the value of a.
- Add the value of b*c to a.
- Find the next prime number and store it in b.
- Negate the value of c as prime numbers are added and subtracted.
- STOP.
Question 2:
Series: 4 12 84 3612...N terms
C∅de:
n,x=int(input("Enter limit - ")),4
for i in range(n):
print(x,end=" ")
x+=(x*x)//2
Algorithm:
- START.
- Accept the limit, say n.
- Initialise x=4.
- Iterate a loop n times.
- Display the value of x.
- Add the value of int(x²/2) to x and x becomes the next term of the series.
- STOP.
See the attachment for output.
Attachments:
Similar questions
Math,
2 months ago
Chemistry,
4 months ago
Math,
4 months ago
English,
11 months ago
Computer Science,
11 months ago