forked from OpenGenus/cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2f8cb2
commit 465de1f
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
code/mathematical_algorithms/src/newman_conway/newman_conway_sequence.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <stdio.h> | ||
|
||
void | ||
newman_conway_sequence(int number_of_terms) | ||
{ | ||
int array[number_of_terms + 1]; | ||
array[0] = 0; | ||
array[1] = 1; | ||
array[2] = 1; | ||
|
||
int i; | ||
for (i = 3; i <= number_of_terms; i++) | ||
array[i] = array[array[i - 1]] + array[i - array[i - 1]]; | ||
|
||
for (i = 1; i <= number_of_terms; i++) | ||
printf("%d ",array[i]); | ||
printf("\n"); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
int number_of_terms = 20; | ||
newman_conway_sequence(number_of_terms); | ||
|
||
return (0); | ||
} |