Printing Lucas Numbers

Problem Statement
 Write a program to display the following series(Lucas number)
    2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123.nth term.
 
   Take n as user input. The first two terms of the series are 2 and 1 respectively and remaining terms are the sum of their previous two terms in the series e.g.,
 
    3 = 1+2
    4 = 3+1

#include<stdio.h>
int main()
{
  int first,temp,second,count,n;
  count=2;
  first=2;
  second=1;
  printf("enter the number of terms to print \n");
  scanf("%d",&n);  
  printf("starts here\n");
  printf("%d %d ",first,seconds);
  while(count<=n)
    {
      temp=second;
      seconds=first+second;
      first=temp;
      printf("%d ",second);
      count++;
    }
  printf("\n");
  return 0;
}



No comments:

Post a Comment