New Question!!!
Without using any Conditional contruct and Strings , print the following series:-
0,5,0,5...Nth term
#ShortestProgramPossible
Answers
Answered by
5
Required Answer:-
Question:
Without using conditional construct and strings, print the following series upto nth term.
0 5 0 5...
Solution:
Here comes the program. This might be the shortest program possible.
n,a,b=int(input("Enter limit - ")),0,5
for i in range(n):
print(a&5,end=" ")
a,b=b,a
If you don't know about bitwise 'and', then you can use this approach.
n=int(input("Enter the range - "))
a,b=0,5
for i in range(n):
print(a,end=" ")
a+=b
b*=-1
Algorithm:
- Accept the limit.
- Initialise a=0 and b=5
- Display the value of a.
- Add value of b to a.
- Negate the value of b.
- Continue this steps n times.
Refer to the attachment for output ☑
Attachments:
Answered by
4
Attachments:
Similar questions