I tried to Write c++ program to check weather is a golden rectangle or not by using Fibonacci series (if Fibonacci term = length the previous Fibonacci series should = the breadth ) that is mean it's a golden rectangle else not golden rectangle .. i get error stack overflow ..!!!
This my code::
#include "stdafx.h"
#include "iostream"
using namespace std;
int fib (int);
int _tmain(int argc, _TCHAR* argv[])
{
int length;
cout << "enter the Length " << endl;
cin>> length ;
int breadth;
cout << "enter the Breadth " << endl;
cin>> breadth ;
int x ;
cout << "enter the limit " << endl;
cin>> x ;
cout << endl ;
for (int i =1 ; i <= x ; i++ )
{
cout << "Fibonacci"<<"=" <<fib(i) <<" "<<"Counter =" << (i) << endl;
if ((breadth == (fib(i)-1)) && ( length == fib(i)))
{
cout << " rectangle";
}
else
{
cout << "This is not rectangle";
}
}
system ("pause");
return 0;
}
int fib (int n)
{
if (n == 1)
return 1;
if (n == 2)
return 2;
return fib (n - 1) + fib (n - 2);
}
Aucun commentaire:
Enregistrer un commentaire