Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by clark ( 12 years ago )
#include<stdio.h>
#include<stdlib.h>

/* function declaration */
void fib_for_loop();
void fib_do_while_loop();
void fib_while_loop();
void instruct_insert();

int main()
{
    puts("=============== Fibonacci In (for loop) ===============\n");
    fib_for_loop();
    
    puts("\n=============== Fibonacci In (while loop loop) ===============\n");
    fib_while_loop();
    
    puts("\n=============== Fibonacci In (do while loop loop) ===============\n");
    fib_do_while_loop();
    
    getch();
}

void fib_for_loop(void){
     /* local variable declaration */
      int first = 0, sec next, i;
     
     instruct_insert();
     
     for ( i = 1 ; i < n ; i++ )
     {
      if ( i <= 1 )
         next = i;
      else
      {
         next = first + second;
         first = second;
          sec
      }
      printf("\n%d\n",next);
    }
     first = 0;
      sec    
}

void fib_while_loop(void){
     /* local variable declaration */
      int first = 0, sec next, i;
     
     instruct_insert();
     
     i = 1;
     while(i < n)
     {
      if ( i <= 1 )
         next = i;
      else
      {
         next = first + second;
         first = second;
          sec
      }
      printf("\n%d\n",next);
      i++;
    }        
}

void fib_do_while_loop(void){
     /* local variable declaration */
      int first = 0, sec next, i;
     
     instruct_insert();
     
     i = 1;
     do
     {
       if ( i <= 1 )
         next = i;
      else
      {
         next = first + second;
         first = second;
          sec
      }
      printf("\n%d\n",next);
      i++;
    }while(i < n);    
}

void instruct_insert(void){
     printf("Enter the number of terms: ");
     scanf("%d",&n);
     printf("\nFirst %d terms of Fibonacci series are :\n", n);     
}

 

Revise this Paste

Your Name: Code Language: