From 680672c4166736738cc53c5c501f71a4fef081a6 Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Sun, 5 Jan 2020 22:13:31 +0530 Subject: [PATCH 01/10] Update Calculator.cpp --- Calculator.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/Calculator.cpp b/Calculator.cpp index aa82b4f..c37e743 100644 --- a/Calculator.cpp +++ b/Calculator.cpp @@ -1,10 +1,19 @@ //Basic Calculator using C++ # include +#include using namespace std; + +template +T find_max(T a, U b) +{ + return a > b ? a : b; +} int main() { - int ch,sum; + int ch; + float sum, sub, mul, div,max; + int mod; float num1, num2; cout << "Enter option \n 1.Addition \t 2. Subtraction \n 3.Multiplication \t 4. Division \n 5. Modulus \t 6. Maximum of two nos \n "; cin >> ch; @@ -13,9 +22,35 @@ int main() switch(ch) { case 1: - sum=num1+num2; - cout<<"Sum of two numbers is "< Date: Sun, 5 Jan 2020 22:16:16 +0530 Subject: [PATCH 02/10] Update Seriesplay.cpp --- Seriesplay.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 149 insertions(+), 6 deletions(-) diff --git a/Seriesplay.cpp b/Seriesplay.cpp index 820932c..e6f81d3 100644 --- a/Seriesplay.cpp +++ b/Seriesplay.cpp @@ -1,4 +1,4 @@ -//Print the following Series using a menu driven program +//Print the following Series using a menu driven program //1. Fibonacci series //2. n natural numbers //3. n prime numbers @@ -10,27 +10,170 @@ //7. 1+2+6+24+120+..... //8. 1/2+2/3+3/4+4/5+.... -# include +#include using namespace std; + +int fib(int n) +{ + if (n == 0 || n == 1) + return 1; + else + return fib(n - 1) + fib(n - 2); +} + +void natural(int n) +{ + for (int i = 1; i <= n; ++i) + { + cout << i << " "; + } + cout << endl; +} + +bool isPrime(int n) +{ + if (n <= 1) + return false; + for (int i = 2; i < n; i++) + if (n % i == 0) + return false; + + return true; +} +void printPrime(int n) +{ + for (int i = 2; i <= n; i++) { + if (isPrime(i)) + cout << i << " "; + } +} + +void even_number(int n) +{ + for (int i = 0; i <= n; i = i + 2) + { + cout << i << " "; + } + cout << endl; +} + +int createPalindrome(int input, int b, bool isOdd) +{ + int n = input; + int palin = input; + if (isOdd) + n /= b; + while (n > 0) + { + palin = palin * b + (n % b); + n /= b; + } + return palin; +} +void generatePalindromes(int n) +{ + int number; + for (int j = 0; j < 2; j++) + { + int i = 1; + while ((number = createPalindrome(i, 10, j % 2)) < n) + { + cout << number << " "; + i++; + } + } +} + +void square_sum(int n) +{ + int sum = 0; + for (int i = 1; i <= n; ++i) + { + sum += i * i; + } + cout << sum << endl; +} + + +int fact(int n) +{ + if (n <= 0) + return 1; + else + return fact(n - 1) * n; +} + +int sum_fact(int n) +{ + int sum1 = 0; + for (int i = 1; i <= n; ++i) + { + sum1 += fact(i); + } + cout << sum1 << endl; +} + +int series(int n) +{ + int a = 1; + float sum_series = 0; + for (int i = 0; i < n; ++i) + { + sum_series += (float) a / (a + 1); + a++; + } + cout << sum_series << endl; +} int main() { int ch; - + cout << "Enter option \n"; cout<<"1. Print Fibonacci series\n"; cout<<"2. n natural numbers\n"; cout<<"3. n prime numbers\n"; cout<<"4. n even numbers\n"; cout<<"5. n pallindrome numbers\n"; - cout<<"6. 1+4+9+16+.....n"; + cout<<"6. 1+4+9+16+.....\n"; cout<<"7. 1+2+6+24+120+.....\n"; cout<<"8. 1/2+2/3+3/4+4/5+....\n"; cin >> ch; - + int n1; + cin >> n1; switch(ch) { case 1: - + cout << fib(n1); + break; + + case 2: + natural(n1); + break; + + case 3: + printPrime(n1); + break; + + case 4: + even_number(n1); + break; + + case 5: + generatePalindromes(n1); + break; + + case 6: + square_sum(n1); + break; + + case 7: + sum_fact(n1); + break; + + case 8: + series(n1); + break; + default: // If the options is not 1-8, error message is shown cout << "Error! Option is not correct"; From 0833efef4c858d7e6ed82461d1beb8480ec2934f Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Sun, 5 Jan 2020 22:17:42 +0530 Subject: [PATCH 03/10] Update CheckCharacter.py --- CheckCharacter.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CheckCharacter.py b/CheckCharacter.py index a507f6b..b1fbe60 100644 --- a/CheckCharacter.py +++ b/CheckCharacter.py @@ -1,3 +1,9 @@ # A program to check if the a character is a Capital Letter, Small Letter,vowel,consonant, Digit or special Character . ch = input("Enter a character: ") #character input +if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')): + print("The Given Character ", ch, "is an Alphabet") +elif(ch >= '0' and ch <= '9'): + print("The Given Character ", ch, "is a Digit") +else: + print("The Given Character ", ch, "is a Special Character") From 89fe4bfb2bf5f11e73cc3c806824354b211ea41b Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Sun, 5 Jan 2020 22:18:32 +0530 Subject: [PATCH 04/10] Update Age_Calculator.cpp --- Age_Calculator.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Age_Calculator.cpp b/Age_Calculator.cpp index 6be2102..369b8b8 100644 --- a/Age_Calculator.cpp +++ b/Age_Calculator.cpp @@ -1,26 +1,25 @@ //Program to check your age till date -#include -#include -void main() +#include +using namespace std; +int main() { -int birth_month,birth_year; -int current_month,current_year; -int ageinyear,ageinmonth; -cout<<"Age Calculator\n\n"; + int birth_month, birth_year; + int current_month, current_year; + int ageinyear, ageinmonth; + cout << "Age Calculator\n\n"; -cout<<"\nEnter Your Birth Month(Eg:8): "; -cin>>birth_month; -cout<<"\nEnter Your Birth Year(Eg:1999): "; -cin>>birth_year; + cout << "\nEnter Your Birth Month(Eg:8): "; + cin >> birth_month; + cout << "\nEnter Your Birth Year(Eg:1999): "; + cin >> birth_year; -cout<<"\nEnter The Current Month(Eg:12): "; -cin>>current_month; -cout<<"\nEnter The Current Year(Eg:2020): "; -cin>>current_year; -ageinyear= ; -ageinmonth= ; -cout<<"\n\nYour Age is "<> current_month; + cout << "\nEnter The Current Year(Eg:2020): "; + cin >> current_year; + ageinyear = current_year - birth_year; + ageinmonth = 12 - birth_month; + cout << "\n\nYour Age is " << ageinyear << " Years And " << ageinmonth << " Months "; } From 478f4ded87e220e472d3a924db92807e96a1dd82 Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Tue, 7 Jan 2020 10:07:34 +0530 Subject: [PATCH 05/10] Add files via upload --- jump_search.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 jump_search.cpp diff --git a/jump_search.cpp b/jump_search.cpp new file mode 100644 index 0000000..79dc0e1 --- /dev/null +++ b/jump_search.cpp @@ -0,0 +1,59 @@ +// +// Created by ankit on 15-07-2019. +// + +#include +using namespace std; + +typedef long long int lli; + +int jumpSearch (vector v, lli n, lli x) { + lli step = sqrt(n); + + lli prev = 0; + + while (v[min(step, n) - 1] < x) + { + prev = step; + step += sqrt(n); + + if (prev >= n) + return -1; + } + + while (v[prev] < x) + { + prev++; + + if (prev == min(step, n)) + return -1; + } + + if (v[prev] == x) + return prev; + + return -1; +} + +int main() +{ + lli t; + cin >> t; + + for (int i = 0; i < t; i++) + { + lli n; + cin >> n; + vector v; + lli input; + + for (int i = 0; i < n; i++) + { + cin >> input; + v.push_back(input); + } + lli k; + cin >> k; + cout << jumpSearch(v, n, k) << endl; + } +} From 874660f5d18fbbf91abbc07ca7edfa94cbf11d4b Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Wed, 8 Jan 2020 18:54:58 +0530 Subject: [PATCH 06/10] Add files via upload --- binary_search1.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 binary_search1.cpp diff --git a/binary_search1.cpp b/binary_search1.cpp new file mode 100644 index 0000000..75ecdee --- /dev/null +++ b/binary_search1.cpp @@ -0,0 +1,34 @@ +// +// Created by ankit on 07-08-2019. +// + +#include +using namespace std; + +typedef int ll; + +int main(void) +{ + ll n, x; + cin >> n >> x; + vector v; + ll input; + for (int i = 0; i < n; i++) + { + cin >> input; + v.push_back(input); + } + ll k = 0; + for (int b = n / 2; b >= 1; b /= 2) + { + while (k + b < n && v[k + b] <= x) + k += b; + } + + if (v[k] == x) + { + cout << "Element found at " << k + 1 << endl; + } + else + cout << "No element found" << endl; +} \ No newline at end of file From fdcaf13539d6ce3961f3f3a7e11e1a9fa3c6dfc1 Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Sun, 12 Jan 2020 23:26:34 +0530 Subject: [PATCH 07/10] Add files via upload --- power.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 power.cpp diff --git a/power.cpp b/power.cpp new file mode 100644 index 0000000..de75c4d --- /dev/null +++ b/power.cpp @@ -0,0 +1,39 @@ +// +// Created by ankit on 05-08-2019. +// + +#include +using namespace std; +typedef long long ll; +typedef int ii; +typedef unsigned u; +int power(ii x, u y) +{ + ii result = 1; + + while (y > 0) + { + if (y & 1) + result = result * x; + + y = y >> 1; + x = x * x; + } + return result; +} +int main(void) +{ + ii x; + u y; + cin >> x >> y; + cout << power(x, y) << endl; +} + + + + + + + + + From 40b037ed81d194a41493536dd2d3021d88c7e1ca Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Sun, 12 Jan 2020 23:33:55 +0530 Subject: [PATCH 08/10] Delete power.cpp --- power.cpp | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 power.cpp diff --git a/power.cpp b/power.cpp deleted file mode 100644 index de75c4d..0000000 --- a/power.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// -// Created by ankit on 05-08-2019. -// - -#include -using namespace std; -typedef long long ll; -typedef int ii; -typedef unsigned u; -int power(ii x, u y) -{ - ii result = 1; - - while (y > 0) - { - if (y & 1) - result = result * x; - - y = y >> 1; - x = x * x; - } - return result; -} -int main(void) -{ - ii x; - u y; - cin >> x >> y; - cout << power(x, y) << endl; -} - - - - - - - - - From db9479ba0cd67ee111bed08ce901c99f2ea90731 Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Sat, 18 Jan 2020 09:46:09 +0530 Subject: [PATCH 09/10] Add files via upload --- 2D_vector.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 2D_vector.cpp diff --git a/2D_vector.cpp b/2D_vector.cpp new file mode 100644 index 0000000..42cbfe4 --- /dev/null +++ b/2D_vector.cpp @@ -0,0 +1,31 @@ +// +// Created by ankit on 12-09-2019. +// + +#include +using namespace std; + +int main() +{ + int row, col; + cin >> row >> col; + vector< vector >v; + v.resize(col,vector(row)); + + for (int i = 0; i < row; i++) + { + for (int j = 0; j < col; j++) + { + cin >> v[i][j]; + } + } + + for (int i = 0; i < row; i++) + { + for (int j = 0; j < col; j++) + { + cout << v[i][j] << " "; + } + cout << endl; + } +} \ No newline at end of file From ed24cd369e7ddd2c49b6978d3fe78eb0009c2dae Mon Sep 17 00:00:00 2001 From: Ankit Raj Date: Sat, 18 Jan 2020 09:49:35 +0530 Subject: [PATCH 10/10] Add files via upload