Sum of Perrin Numbers | C ++ program to calculate sum of Perrin Numbers ; function for sum of first n Perrin number . ; if ( n == 0 ) n = 0 ; if ( n == 1 ) n = 1 ; if ( n == 2 ) n = 2 ; calculate k = 5 sum of three previous step . ; Sum remaining numbers ; int d = a + b ; calculate next term ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int calSum ( int n ) { int a = 3 , b = 0 , c = 2 ; return 3 ; return 3 ; return 5 ; int sum = 5 ; while ( n > 2 ) { sum += d ; a = b ; b = c ; c = d ; n -- ; } return sum ; } int main ( ) { int n = 9 ; cout << calSum ( n ) ; return 0 ; }