-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* factorial in c++ * fibonacci recursion * c++ code for day14
- Loading branch information
1 parent
4cb3ac6
commit aeee124
Showing
2 changed files
with
87 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,47 @@ | ||
/** | ||
* @author: Karthick < karthikn2099@gmail.com > | ||
* @github: https://github.com/karthikn2098 | ||
* @date: 08/01/2018 | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int product(int number , int times) { | ||
|
||
//if multiplier is a negative number. | ||
if(times < 0) { | ||
return number + product(number , times+1); | ||
} | ||
|
||
if(times == 0) { | ||
return 0; | ||
} | ||
|
||
return number + product(number , times-1); | ||
} | ||
|
||
int main(void) { | ||
|
||
int A , B; | ||
|
||
cout << "Enter A & B: " ; | ||
cin >> A >> B; | ||
|
||
cout << "Product of " << A << " & " << B << " = " << product(A , B); | ||
|
||
return 0; | ||
} | ||
|
||
/* | ||
--------------------- | ||
Sample Input/Output | ||
--------------------- | ||
1) Enter A & B: 10 5 | ||
Product of 10 & 5 = 50 | ||
2) Enter A & B: -2 -3 | ||
Product of -2 & -3 = -6 | ||
*/ |
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,40 @@ | ||
/** | ||
* @author: Karthick < karthikn2099@gmail.com > | ||
* @github: https://github.com/karthikn2098 | ||
* @date: 08/01/2018 | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int sumOfDigits(int N) { | ||
|
||
if( N == 0 ) { | ||
return 0; | ||
} | ||
return ( sumOfDigits(N/10) + N%10 ); | ||
|
||
} | ||
|
||
int main(void) { | ||
|
||
int N; | ||
|
||
cout << "Enter the Number: "; | ||
cin >> N; | ||
|
||
cout << "\nThe sum of digits = " << sumOfDigits(N); | ||
|
||
return 0; | ||
} | ||
|
||
/* | ||
--------------------- | ||
Sample Input/Output | ||
--------------------- | ||
Enter the Number: 1234 | ||
The sum of digits = 10 | ||
*/ |