Lucas Numbers | Iterative C / C ++ program to find n 'th Lucas Number ; Iterative function ; declaring base values for positions 0 and 1 ; generating number ; Driver Code
#include <stdio.h> NEW_LINE int lucas ( int n ) { int a = 2 , b = 1 , c , i ; if ( n == 0 ) return a ; for ( i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return b ; } int main ( ) { int n = 9 ; printf ( " % d " , lucas ( n ) ) ; return 0 ; }