diff --git a/C++/Program 22/adding_two_string.cpp b/C++/Program 22/adding_two_string.cpp new file mode 100644 index 00000000..68c0b973 --- /dev/null +++ b/C++/Program 22/adding_two_string.cpp @@ -0,0 +1,59 @@ +/* +Program : To add 2 string + +this Program is Contributed by Abhishek Jaiswal +*/ + +#include +using namespace std; + +int Len(string &str1, string &str2) +{ + int len1 = str1.size(); + int len2 = str2.size(); + if (len1 < len2) + { + for (int i = 0 ; i < len2 - len1 ; i++) + str1 = '0' + str1; + return len2; + } + else if (len1 > len2) + { + for (int i = 0 ; i < len1 - len2 ; i++) + str2 = '0' + str2; + } + return len1; +} + +string add( string a, string b ) +{ + string result; + int len = Len(a, b); + + int carry = 0; + for (int i = len-1 ; i >= 0 ; i--) + { + int aBit = a.at(i) - '0'; + int bBit = b.at(i) - '0'; + int sum = (aBit ^ bBit ^ carry)+'0'; + + result = (char)sum + result; + carry = (aBit & bBit) | (bBit & carry) | (aBit & carry); + } + + if (carry) + result = '1' + result; + + return result; +} + +int main() +{ + string str1,str2; + cout<<"Enter the string 1 :"; + cin>>str1; + cout<<"Enter the string 2 :"; + cin>>str2; + cout << "Sum is " << add(str1, str2); + return 0; +} diff --git a/C++/Program 22/readme.md b/C++/Program 22/readme.md new file mode 100644 index 00000000..1144c04b --- /dev/null +++ b/C++/Program 22/readme.md @@ -0,0 +1,3 @@ +Program : To add Two Binary Number +Input : Two Number consitising of 0 and 1 +Output : Number Constisting of 0 and 1 diff --git a/C++/Program 23/readme.md b/C++/Program 23/readme.md new file mode 100644 index 00000000..33afe4b7 --- /dev/null +++ b/C++/Program 23/readme.md @@ -0,0 +1,4 @@ +Program :To find the sum of square of binomial coefficient +Input : Integer +Output : Integer + diff --git a/C++/Program 23/sum_of_square_of_binomial_coefficient.cpp b/C++/Program 23/sum_of_square_of_binomial_coefficient.cpp new file mode 100644 index 00000000..032034db --- /dev/null +++ b/C++/Program 23/sum_of_square_of_binomial_coefficient.cpp @@ -0,0 +1,32 @@ +/* +Program :To find the sum of square of +binomial coefficient. + +This Program is contributed by Abhishek Jaiswal +*/ +#include +using namespace std; + +int factorial(int begin, int end) +{ + int num = 1; + for (int i = begin; i <= end; i++) + num *= i; + + return num; +} + +int square(int n) +{ + return factorial(n + 1, 2 * n) / factorial(1, n); +} + +int main() +{ + int n; + cout << "Enter the number :"; + cin >> n; + cout << "The Sum of Square is " << square(n) << endl; + return 0; +} +