1

Need a help, how can i print arr pointer with value of arrfibo[] on fibo function ?

#include <iostream>
using namespace std;

int fibo(int input){

    for(int i=0;i<input;i++){
        if(i<2){
            arrfibo[i] = i;
        }else{
            arrfibo[i] = arrfibo[i-2] + arrfibo[i-1];
        }
    }   
}

main(){
    int inp;
    cout << "Enter number of fibonancci = ";
    cin >> inp;
    int *arr;

    // how can i print arr pointer with value of arrfibo[] on fibo function ?   
}

thanks for any answer,

1
  • main() is a syntax error. Commented Dec 5, 2016 at 0:29

1 Answer 1

1
int main(){
     int inp;
     cout << "Enter number of fibonacci = ";
     cin >> inp;
     int *arr = new int[inp];
     fibo(inp, arr);
     //Any additional code
     //Delete dynamic memory.
     delete [] arr;
     }

Then modify fibo as:

void fibo(int input, int* arrfibo){

for(int i=0;i<input;i++){
    if(i<2){
        arrfibo[i] = i;
    }else{
        arrfibo[i] = arrfibo[i-2] + arrfibo[i-1];
    }
}   
 //Use arrfibo at your will after this point.
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.