Skip to content

Commit 9d24fa7

Browse files
committed
added files to mathematics folder in cpp
1 parent 150458a commit 9d24fa7

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Mathematics/GCD/LcmAndGcd.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main(){
5+
int a,b,result;
6+
cout<<"Enter two numbers = ";
7+
cin>>a>>b;
8+
#using stl for finding gcd of 2 numbers..
9+
result=__gcd(a,b);
10+
cout<<"GCD is= "<<result;
11+
cout<<"LCM is="<<(a*b)/result;
12+
13+
}
14+
return 0;
15+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int t1 = 0, t2 = 1, nextTerm = 0, n;
7+
8+
cout << "Enter a positive number: ";
9+
cin >> n;
10+
11+
// displays the first two terms which is always 0 and 1
12+
cout << "Fibonacci Series: " << t1 << ", " << t2 << ", ";
13+
14+
nextTerm = t1 + t2;
15+
16+
while(nextTerm <= n)
17+
{
18+
cout << nextTerm << ", ";
19+
t1 = t2;
20+
t2 = nextTerm;
21+
nextTerm = t1 + t2;
22+
}
23+
return 0;
24+
}

0 commit comments

Comments
 (0)