Write a program which accepts a single unsigned integer para
Write a program which accepts a single unsigned integer parameter n, calculate the first n Lucas numbers, stores them in an array and the prints the Lucas numbers, the sum of the Lucas numbers and all of the even Lucas numbers
Solution
#include <iostream>
 using namespace std;
int main(void)
 {
    int n;
    cout<<\"Please enter a positive number:\";
    cin>>n;
    int a[n];
    a[0]=2;
    a[1]=1;
    for(int i=2;i<n;i++)
    {
        a[i] = a[i-1]+a[i-2];
    }
    int sum=0;
    cout<<\"The first \"<<n<<\" lucas numbers are: \";
    for(int i=0;i<n;i++)
    {
        cout<< a[i]<<\' \';
        sum += a[i];
    }
    cout<<endl;
cout<<\"The sum of first \"<<n<<\" lucas numbers is:\"<<sum<<endl;
   cout<<\"The even numbers in first \"<<n<<\" lucas numbers are: \";
    for(int i=0;i<n;i++)
    {
        if(a[i]%2==1)continue;
        cout<< a[i]<<\' \';
        //sum += a[i];
    }
    cout<<endl;
   return 0;
 }

