Skip to content

Commit aeee124

Browse files
Karthikn2099MadhavBahl
authored andcommitted
c++ code for day14 (#144)
* factorial in c++ * fibonacci recursion * c++ code for day14
1 parent 4cb3ac6 commit aeee124

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @author: Karthick < karthikn2099@gmail.com >
3+
* @github: https://github.com/karthikn2098
4+
* @date: 08/01/2018
5+
*/
6+
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
10+
int product(int number , int times) {
11+
12+
//if multiplier is a negative number.
13+
if(times < 0) {
14+
return number + product(number , times+1);
15+
}
16+
17+
if(times == 0) {
18+
return 0;
19+
}
20+
21+
return number + product(number , times-1);
22+
}
23+
24+
int main(void) {
25+
26+
int A , B;
27+
28+
cout << "Enter A & B: " ;
29+
cin >> A >> B;
30+
31+
cout << "Product of " << A << " & " << B << " = " << product(A , B);
32+
33+
return 0;
34+
}
35+
36+
/*
37+
---------------------
38+
Sample Input/Output
39+
---------------------
40+
41+
1) Enter A & B: 10 5
42+
Product of 10 & 5 = 50
43+
44+
2) Enter A & B: -2 -3
45+
Product of -2 & -3 = -6
46+
47+
*/

day14/C++/sum_of_digits.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @author: Karthick < karthikn2099@gmail.com >
3+
* @github: https://github.com/karthikn2098
4+
* @date: 08/01/2018
5+
*/
6+
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
10+
int sumOfDigits(int N) {
11+
12+
if( N == 0 ) {
13+
return 0;
14+
}
15+
return ( sumOfDigits(N/10) + N%10 );
16+
17+
}
18+
19+
int main(void) {
20+
21+
int N;
22+
23+
cout << "Enter the Number: ";
24+
cin >> N;
25+
26+
cout << "\nThe sum of digits = " << sumOfDigits(N);
27+
28+
return 0;
29+
}
30+
31+
/*
32+
---------------------
33+
Sample Input/Output
34+
---------------------
35+
36+
Enter the Number: 1234
37+
38+
The sum of digits = 10
39+
40+
*/

0 commit comments

Comments
 (0)