Posts

Showing posts with the label Reference

In C++, Generate Next Fibonacci Series Using Call by Reference To Function

Image
#include<iostream> using namespace std; void nextFibo(int &f1, int &f2) { int f3 = f1 + f2; f1 = f2; f2 = f3; } int main(){ int f1 = 1, f2 = 1; for(int i = 1; 10 >= i; i++){ cout << f1 << ' '; nextFibo(f1, f2); } cout << endl; return 0; }