aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNataliia Brown <[email protected]>2024-02-01 12:10:09 -0800
committerNataliia Brown <[email protected]>2024-02-01 12:10:09 -0800
commitd76610116c41c36d8a2c87c329ab9e2f9f729ef8 (patch)
treeb0e236b7657d0ab80ab25fcb57992c8908656bc3
parentInitial commit (diff)
downloadhomework-3-natabrown-d76610116c41c36d8a2c87c329ab9e2f9f729ef8.tar.xz
homework-3-natabrown-d76610116c41c36d8a2c87c329ab9e2f9f729ef8.zip
added fibonacci
-rw-r--r--Homework-3/Homework-3/Header.h15
-rw-r--r--Homework-3/Homework-3/Homework_3.cpp41
2 files changed, 42 insertions, 14 deletions
diff --git a/Homework-3/Homework-3/Header.h b/Homework-3/Homework-3/Header.h
index f9ce46e..d6a5e84 100644
--- a/Homework-3/Homework-3/Header.h
+++ b/Homework-3/Homework-3/Header.h
@@ -1,13 +1,14 @@
#ifndef MY_HEADER_FILE_h
#define MY_HEADER_FILE_h
-//int math_func();
-//
-//int math_func(int square);
-//
-//int math_func(int a, int b);
-//
-//int math_func(int A, int B, int C, int x = 2);
+
+long factorial(int a);
+int fibonacci(int x);
+
+
+
+
+
#endif \ No newline at end of file
diff --git a/Homework-3/Homework-3/Homework_3.cpp b/Homework-3/Homework-3/Homework_3.cpp
index c8c59dc..579876e 100644
--- a/Homework-3/Homework-3/Homework_3.cpp
+++ b/Homework-3/Homework-3/Homework_3.cpp
@@ -4,18 +4,45 @@
// Assignment: Homework 3
#include <iostream>
-
+using namespace std;
#include "Header.h"
+
+
int main()
{
- /*std::cout << math_func() << std::endl;
+
+ std::cout << factorial(5) << std::endl;
+
+
+ int x, i = 0;
+ cout << "Enter the term number : ";
+ cin >> x;
+ while (i < x) {
+
+ i++;
+ }
+ cout << " " << fibonacci(x) << " is " << x << "'th term";
+ return 0;
+}
+
+long factorial(int a) {
+ if (a == 0 || a == 1)
+ return 1;
+ return a * factorial(a - 1);
+ }
- std::cout << math_func(2) << std::endl;
- std::cout << math_func(2, 4) << std::endl;
- std::cout << math_func(5, 7, 8) << std::endl;*/
+int fibonacci(int x) {
+ if ((x == 1) || (x == 0)) {
+ return(x);
+ }
+ else {
+ return(fibonacci(x - 1) + fibonacci(x - 2));
+ }
+}
- return 0;
-} \ No newline at end of file
+
+
+