Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* day13 code and readme * day14 code and readme * day15 code and readme
- Loading branch information
1 parent
60ab08d
commit e95409b
Showing
8 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @author:divyakhetan | ||
* @date: 10/1/2019 | ||
*/ | ||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
|
||
int fact(int n){ | ||
if(n == 1) return 1; | ||
else return n * fact(n - 1); | ||
} | ||
|
||
|
||
int main(){ | ||
|
||
int n; | ||
cin >> n; | ||
|
||
cout << "The factorial is " << fact(n); | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @author:divyakhetan | ||
* @date: 10/1/2019 | ||
*/ | ||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
|
||
int fibo(int n){ | ||
if(n <= 2) return 1; | ||
else return fibo(n - 1) + fibo(n - 2); | ||
} | ||
int main(){ | ||
|
||
int n; | ||
cin >> n; | ||
|
||
cout << "The " << n << "th fibonacci number is " << fibo(n) << endl; | ||
|
||
for(int i = 1; i <= n; i++){ | ||
if(i == n){ | ||
cout << fibo(i); | ||
} | ||
else{ | ||
cout << fibo(i) << " , "; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* @author:divyakhetan | ||
* @date: 10/1/2019 | ||
*/ | ||
|
||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
|
||
int product(int a, int b){ | ||
if(b == 0) return 0; // base case; | ||
int ans = product(a, b/2); | ||
if(b % 2 == 0) return 2 * ans; | ||
else return 2 * ans + a; | ||
} | ||
int main(){ | ||
int num1, num2; | ||
cin >> num1 >> num2; | ||
int ans = product(num1, num2); | ||
//since we are adding the first number in the recursive function, we get the ans only according to the num1, hence we need to adjust the sign accd to the num2. | ||
if( (num2 < 0 && num1 > 0) || (num2 < 0 && num1 < 0)) ans *= -1; | ||
cout << "The multiplication is " << ans; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @author:divyakhetan | ||
* @date: 10/1/2019 | ||
*/ | ||
|
||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
|
||
int sum(int n){ | ||
if(n < 10) return n; | ||
else return n % 10 + sum(n /10); | ||
} | ||
int main(){ | ||
int n; | ||
cin >> n; | ||
cout << "The sum of digits is " << sum(n); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @author:divyakhetan | ||
* @date: 10/1/2019 | ||
*/ | ||
|
||
|
||
#include<bits/stdc++.h> | ||
using namespace std; | ||
|
||
int pascal(int i, int j){ | ||
if(j == 1) return 1; | ||
if(i == j ) return 1; | ||
else return pascal(i - 1, j) + pascal(i - 1, j - 1); | ||
} | ||
|
||
int main(){ | ||
int n; | ||
cin >> n; | ||
|
||
for(int i = 1; i <= n; i++){ | ||
for(int j = 1; j <= i; j++){ | ||
cout << pascal(i,j) << " "; | ||
} | ||
cout << endl; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters