From e391f385eeb9278efe7ff188e7e5b2ce97a14153 Mon Sep 17 00:00:00 2001 From: Arceus-sj <71997730+Arceus-sj@users.noreply.github.com> Date: Thu, 1 Oct 2020 15:58:31 +0530 Subject: [PATCH 1/6] Add files via upload --- C++/number_of_occurrence.cpp | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 C++/number_of_occurrence.cpp diff --git a/C++/number_of_occurrence.cpp b/C++/number_of_occurrence.cpp new file mode 100644 index 00000000..733dcfb9 --- /dev/null +++ b/C++/number_of_occurrence.cpp @@ -0,0 +1,42 @@ +#include + +using namespace std; + +class Solution{ +public: + +/* + if x is present in arr[] then returns the count + of occurrences of x, otherwise returns 0. +*/ + +int count(int arr[], int n, int x) { + + int count = 0; + for(int i=0;i> n ; + cout<<"Enter a number to be counted: "; + cin>>x; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + } + Solution ob; + auto ans = ob.count(arr, n, x); + cout<< "number "< Date: Thu, 1 Oct 2020 16:10:26 +0530 Subject: [PATCH 2/6] Create Readme.md --- C++/Readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 C++/Readme.md diff --git a/C++/Readme.md b/C++/Readme.md new file mode 100644 index 00000000..dba37502 --- /dev/null +++ b/C++/Readme.md @@ -0,0 +1,7 @@ +Program 2: + +Write a Program to find the number of occurrence of X element present in sorted array. +Variable description--> +n = size of array/ number of element +x = Element to be counted in array +count = veriable to count the X-number in array From 9a910282e34d71893a959f69c19e04dda0f6047d Mon Sep 17 00:00:00 2001 From: Arceus-sj <71997730+Arceus-sj@users.noreply.github.com> Date: Thu, 1 Oct 2020 16:12:18 +0530 Subject: [PATCH 3/6] Rename C++/Readme.md to C++/Program-2/Readme.md --- C++/{ => Program-2}/Readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename C++/{ => Program-2}/Readme.md (100%) diff --git a/C++/Readme.md b/C++/Program-2/Readme.md similarity index 100% rename from C++/Readme.md rename to C++/Program-2/Readme.md From 7751e09ec19f4d7f158aba4d36693d0202dcd1d2 Mon Sep 17 00:00:00 2001 From: Arceus-sj <71997730+Arceus-sj@users.noreply.github.com> Date: Thu, 1 Oct 2020 16:13:10 +0530 Subject: [PATCH 4/6] Rename C++/number_of_occurrence.cpp to C++/Program-2/number_of_occurrence.cpp --- C++/{ => Program-2}/number_of_occurrence.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename C++/{ => Program-2}/number_of_occurrence.cpp (94%) diff --git a/C++/number_of_occurrence.cpp b/C++/Program-2/number_of_occurrence.cpp similarity index 94% rename from C++/number_of_occurrence.cpp rename to C++/Program-2/number_of_occurrence.cpp index 733dcfb9..d481a7bc 100644 --- a/C++/number_of_occurrence.cpp +++ b/C++/Program-2/number_of_occurrence.cpp @@ -39,4 +39,4 @@ int main() { auto ans = ob.count(arr, n, x); cout<< "number "< Date: Thu, 1 Oct 2020 17:14:26 +0530 Subject: [PATCH 5/6] Create swap_kth_Element.cpp --- C++/Program-3/swap_kth_Element.cpp | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 C++/Program-3/swap_kth_Element.cpp diff --git a/C++/Program-3/swap_kth_Element.cpp b/C++/Program-3/swap_kth_Element.cpp new file mode 100644 index 00000000..d0573268 --- /dev/null +++ b/C++/Program-3/swap_kth_Element.cpp @@ -0,0 +1,45 @@ +#include + +using namespace std ; + +void takeInput(int a[], int n){ + for(int i=1;i<=n;i++){ + cin>>a[i]; + } +} + +void swap_k(int a[], int n, int k){ + + int i , count = n ; + for(i=1 ; i<=n , count >= 1 ; i++ , count--){ + + if(k == i || k == count){ + swap(a[k],a[count]); + } + + } + + for(i=1;i<=n;i++){ + cout<>n ; + + int k; + cout<<"Enter Kth element to swap:"; + cin>>k ; + + int a[1000]; + takeInput(a,n); + + swap_k(a,n,k); + cout<<"\n"; + + return 0; +} From 56aabbff5319ffca1dacb699a017c127aca4bc4e Mon Sep 17 00:00:00 2001 From: Arceus-sj <71997730+Arceus-sj@users.noreply.github.com> Date: Thu, 1 Oct 2020 17:21:13 +0530 Subject: [PATCH 6/6] Create Readme.md --- C++/Program-3/Readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 C++/Program-3/Readme.md diff --git a/C++/Program-3/Readme.md b/C++/Program-3/Readme.md new file mode 100644 index 00000000..7d8ad5bd --- /dev/null +++ b/C++/Program-3/Readme.md @@ -0,0 +1,4 @@ +Program to Swap the Kth Elements of a series. +variable description --> +n = number of elements/size +k = Kth element for swaping