Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <stdio.h>
- #include <stdlib.h>
- typedef struct node{
- int n;
- struct node* _next;
- } Node;
- void fibo_o(Node *prev, Node *first, int n){
- Node *new_node = malloc(sizeof(Node));
- if(n==0){
- prev->_next->_next=first;
- return;
- }
- new_node->n = prev->n+prev->_next->n;
- prev->_next->_next=new_node;
- fibo_o(prev->_next, first, n-1);
- printf("%d,", new_node->n);
- }
- void fibo(float n){
- Node *second = malloc(sizeof(Node));
- Node *first = malloc(sizeof(Node));
- if(((float) n) != ((int) n) || n<0){
- printf("Invalid number\n");
- return;
- }
- if(n==0){
- first->_next=first;
- printf("1\n");
- return;
- }
- first->n=second->n=1;
- first->_next = second;
- fibo_o(first, first, (int)(n-1));
- printf("1,1\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement