File tree Expand file tree Collapse file tree 2 files changed +87
-0
lines changed
Expand file tree Collapse file tree 2 files changed +87
-0
lines changed Original file line number Diff line number Diff line change 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+ */
Original file line number Diff line number Diff line change 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 << " \n The 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+ */
You can’t perform that action at this time.
0 commit comments