From 23aa5c1b24b2b6222f7c2154bc96920df37c7896 Mon Sep 17 00:00:00 2001 From: karishmarajput Date: Sun, 31 Oct 2021 13:42:43 +0530 Subject: Add ch-122 solution in js --- challenge-122/karishma/js/ch-1.js | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 challenge-122/karishma/js/ch-1.js diff --git a/challenge-122/karishma/js/ch-1.js b/challenge-122/karishma/js/ch-1.js new file mode 100644 index 0000000000..c6be964b11 --- /dev/null +++ b/challenge-122/karishma/js/ch-1.js @@ -0,0 +1,6 @@ +let input = [10,20,30,40,50]; +let sum = 0; +for (let j = 1; j <= 5; j++) { + sum += input[j-1]; + console.log(sum/j); +} \ No newline at end of file -- cgit From d90ac3c7ece6997c41d3351a69f6a25d340e9e9d Mon Sep 17 00:00:00 2001 From: karishmarajput Date: Sun, 31 Oct 2021 14:08:38 +0530 Subject: Add solution of ch-122-1 in c++ and add stdlib in c solution --- challenge-122/karishma/C/ch-1.c | 30 ++++++++++++++++++++++++++++++ challenge-122/karishma/c++/ch1 | Bin 0 -> 17320 bytes challenge-122/karishma/c++/ch1.cpp | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 challenge-122/karishma/C/ch-1.c create mode 100755 challenge-122/karishma/c++/ch1 create mode 100644 challenge-122/karishma/c++/ch1.cpp diff --git a/challenge-122/karishma/C/ch-1.c b/challenge-122/karishma/C/ch-1.c new file mode 100644 index 0000000000..d52a21d311 --- /dev/null +++ b/challenge-122/karishma/C/ch-1.c @@ -0,0 +1,30 @@ +#include +#include + +int main() { + int n=0; + int* ptr; + printf("Enter total number of inputs to be entered: "); + scanf("%d", &n); + ptr = (int*)calloc(n, sizeof(int)); + if (ptr == NULL) { + printf("Memory not allocated.\n"); + exit(0); + } + else { + for (int i = 1; i <= n; i++) { + int temp=0; + scanf("%d",&temp); + ptr[i] = temp; + } + printf("\n"); + } + int sum = 0; + for (int j = 1; j <= n; j++) { + sum += ptr[j]; + printf("%d ", sum / j); + } + printf("\n"); + free(ptr); + return 0; +} \ No newline at end of file diff --git a/challenge-122/karishma/c++/ch1 b/challenge-122/karishma/c++/ch1 new file mode 100755 index 0000000000..97181945e7 Binary files /dev/null and b/challenge-122/karishma/c++/ch1 differ diff --git a/challenge-122/karishma/c++/ch1.cpp b/challenge-122/karishma/c++/ch1.cpp new file mode 100644 index 0000000000..78da573d58 --- /dev/null +++ b/challenge-122/karishma/c++/ch1.cpp @@ -0,0 +1,33 @@ +#include +using namespace std; + +int main() { + int n=5; + int ptr[]={10,20,30,40,50}; + //int* ptr; + // cout<<"Enter total number of inputs to be entered: "; + // cin>>n; + // ptr = (int*)calloc(n, sizeof(int)); + // if (ptr == NULL) { + // cout<<"Memory not allocated.\n"; + // exit(0); + // } + // else { + // for (int i = 1; i <= n; i++) { + // int temp=0; + // scanf("%d",&temp); + // ptr[i] = temp; + // } + // cout< Date: Sun, 31 Oct 2021 14:12:03 +0530 Subject: clean code ch1.cpp --- challenge-122/karishma/c++/ch1.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/challenge-122/karishma/c++/ch1.cpp b/challenge-122/karishma/c++/ch1.cpp index 78da573d58..821e88134d 100644 --- a/challenge-122/karishma/c++/ch1.cpp +++ b/challenge-122/karishma/c++/ch1.cpp @@ -4,22 +4,6 @@ using namespace std; int main() { int n=5; int ptr[]={10,20,30,40,50}; - //int* ptr; - // cout<<"Enter total number of inputs to be entered: "; - // cin>>n; - // ptr = (int*)calloc(n, sizeof(int)); - // if (ptr == NULL) { - // cout<<"Memory not allocated.\n"; - // exit(0); - // } - // else { - // for (int i = 1; i <= n; i++) { - // int temp=0; - // scanf("%d",&temp); - // ptr[i] = temp; - // } - // cout<