
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print n terms of Newman-Conway Sequence
Newman-Conway Sequence is used for generating following integer sequence.
1 1 2 2 3 4 4 4 5 6 7 7 8 8 8 8 9 10 11 12
Formula used for generating Newman-Conway sequence for n numbers is −
P(n) = P(P(n - 1)) + P(n - P(n - 1)) Where, p(1) =p(2) =1
Algorithm
START Step 1 -> Input variable n(e.g. 20) Step 2 -> start variables as i, p[n+1], p[1]=1, p[2]=1 Step 3 -> Loop For i=3 and i<=n and i++ Set p[i] = p[p[i - 1]] + p[i - p[i - 1]] Print p[i] Step 4 -> End Loop For STOP
Example
#include<stdio.h> int main() { int n = 20,i; int p[n + 1]; p[1] = 1; p[2] = 1; printf("Newman-Conway Sequence is :"); printf("%d %d ",p[1],p[2]); for (i = 3; i <= n; i++) { p[i] = p[p[i - 1]] + p[i - p[i - 1]]; printf("%d ",p[i]); } return 0; }
Output
if we run above program then it will generate following output.
Newman-Conway Sequence is :1 1 2 2 3 4 4 4 5 6 7 7 8 8 8 8 9 10 11 12
- Related Questions & Answers
- Print first N terms of series (0.25, 0.5, 0.75, …) in fraction representation
- Conway’s Game Of Life using Python?
- Find duplicate element in a progression of first n terms JavaScript
- Minimum number of power terms with sum equal to n using C++.
- Find sum of the series ?3 + ?12 +.... upto N terms in C++
- Print numbers in sequence using thread synchronization
- Sum of the series 0.7, 0.77, 0.777 … upto n terms in C++
- How to print the Fibonacci Sequence using Python?
- Print first m multiples of n in C#
- Find sum of the series 1+22+333+4444+... upto n terms in C++
- Python program to print a checkboard pattern of n*n using numpy.
- Python program to print check board pattern of n*n using numpy
- Match any string containing a sequence of N p's
- Sum of the first N terms of the series 2,10, 30, 68,…. in C programming
- Sum of the first N terms of the series 5,12, 23, 38…. in C Programming
Advertisements