hanojiang 1 anno fa
parent
commit
a0b3874116
1 ha cambiato i file con 28 aggiunte e 1 eliminazioni
  1. 28 1
      EssentialCpp/main.cpp

+ 28 - 1
EssentialCpp/main.cpp

@@ -2,6 +2,33 @@
 
 using namespace std;
 
+bool Fibon_Elem(int pos, int& elem) {
+	bool ret = false;
+	elem = 1;
+	int first = 1, second = 1;
+	
+	if (pos <= 0) {
+		return ret;
+	}
+
+	for (int ix = 3; ix <= pos; ++ix) {
+		elem = first + second;
+		first = second;
+		second = elem;
+	}
+	return true;
+}
+
+ 
 int main() {
-	cout << "hello world!" << endl;
+	int elem = 0;
+	bool ret = false;
+	for (int i = 0; i < 10; ++i) {
+		ret = Fibon_Elem(i, elem);
+		if (!ret)
+			cout << "Position " << i <<" is invalid!" << endl;
+		else
+			cout << "ret=" << ret << " " << elem << endl;
+	}
+	
 }