Computer Science, asked by anindyaadhikari13, 3 months ago

Challenge for all programmers.
Language: Python.
Display the given pattern.

1
11
101
1001
10001

Restrictions:
• Don't use any conditional constructs.​

Answers

Answered by ankushrathour2004
3

Answer:

Program to print modified Binary triangle pattern

Given an integer N, the task is to print the modified binary tree pattern.

In Modified Binary Triangle Pattern, the first and last element of a Nth row are 1 and the middle (N – 2) elements are 0.

Examples:

Input: N = 6

Output:

1

11

101

1001

10001

100001

Input: N = 3

Output:

1

11

101

Answered by Oreki
6

{\bf Approach}

   \begin{center}\begin{footnotesize}\textsf{Given pattern contains binary numbers and converting those binary numbers to decimal gives us,}\\\texttt{1, 3, 5, 9, 17, ...}\\\textsf{A pattern can be clearly observed starting from the second number in the series as,}\\2^1 + 1, \: 2^2 + 1, \: 2^3 + 1, \: 2^4 + 1 ...\\\textsf{And the $n^{th}$ term of the series \texttt{(3, 5, 9 ...)} can be inferred as,}\\a_n = 2^n + 1\\\textsf{Hence, using this we can generate the pattern easily.}\end{footnotesize}\end{center}

{\large\bf C\symbol{111}de}

    \texttt{pattern = "1"}\\\texttt{for i in range(0, int(inp\symbol{117}t("Enter N - "))):}\\\texttt{\hspace{1em} print(pattern)}\\\texttt{\hspace{1em} pattern = format(pow(2, i + 1) + 1, "b")}

{\large\bf Checklist}

   \textsf{No conditional constructs  \checkmark}

Attachments:
Similar questions