Skip to content

Commit

Permalink
c++ code for day14 (#144)
Browse files Browse the repository at this point in the history
* factorial in c++

* fibonacci recursion

* c++ code for day14
  • Loading branch information
Karthikn2099 authored and MadhavBahl committed Jan 8, 2019
1 parent 4cb3ac6 commit aeee124
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
47 changes: 47 additions & 0 deletions day14/C++/product_of_two_numbers.cpp
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
*/
40 changes: 40 additions & 0 deletions day14/C++/sum_of_digits.cpp
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
*/

0 comments on commit aeee124

Please sign in to comment.