Skip to content

Commit bbd75f4

Browse files
profgrammerMadhavBahl
authored andcommitted
Cpp day 15 (#153)
* cpp code for day 7 and 8 * fixed readme merge conflict * cpp code for day 15 * Update README.md
1 parent 411afe3 commit bbd75f4

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

day15/C++/profgrammer_pascal.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
*@author: profgrammer
3+
*@date: 09-01-2019
4+
*/
5+
6+
#include <bits/stdc++.h>
7+
using namespace std;
8+
9+
int ncr(int n, int r){
10+
if(n < r || n < 0 || r < 0) return 0;
11+
if(n == r || r == 0) return 1;
12+
return ncr(n-1,r) + ncr(n-1, r-1);
13+
}
14+
15+
int main() {
16+
int n;
17+
cin>>n;
18+
for(int i = 0;i <= n;i++){
19+
for(int j = 0;j <= i;j++) cout<<ncr(i,j)<<" ";
20+
cout<<endl;
21+
}
22+
}

day15/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,33 @@ int main(){
8282
}
8383
```
8484
85+
## [C++ Solution by @profgrammer](./C++/profgrammer_pascal.cpp)
86+
87+
```cpp
88+
/*
89+
*@author: profgrammer
90+
*@date: 09-01-2019
91+
*/
92+
93+
#include <bits/stdc++.h>
94+
using namespace std;
95+
96+
int ncr(int n, int r){
97+
if(n < r || n < 0 || r < 0) return 0;
98+
if(n == r || r == 0) return 1;
99+
return ncr(n-1,r) + ncr(n-1, r-1);
100+
}
101+
102+
int main() {
103+
int n;
104+
cin>>n;
105+
for(int i = 0;i <= n;i++){
106+
for(int j = 0;j <= i;j++) cout<<ncr(i,j)<<" ";
107+
cout<<endl;
108+
}
109+
}
110+
```
111+
85112
## Python Implementation
86113

87114
### [Solution] (./Python/pascal.py)
@@ -189,4 +216,5 @@ def main():
189216
print(f'Pascal triangle cannot have {num} rows')
190217

191218
main()
219+
192220
```

day8/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ int main() {
288288
getline(cin, first);
289289
getline(cin, second);
290290
cout << "The Levenshtein distance between \"" << first << "\" and \"" << second << "\" is: " << dist(first, second) << endl;
291-
}
291+
}
292292
```
293293

294294
### C Implementation

0 commit comments

Comments
 (0)