aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkarishmarajput <karrajput3948@gmail.com>2021-10-31 14:08:38 +0530
committerkarishmarajput <karrajput3948@gmail.com>2021-10-31 14:08:38 +0530
commitd90ac3c7ece6997c41d3351a69f6a25d340e9e9d (patch)
tree287019c8c47b05aa6782810e93ec542a47db851b
parent23aa5c1b24b2b6222f7c2154bc96920df37c7896 (diff)
downloadperlweeklychallenge-club-d90ac3c7ece6997c41d3351a69f6a25d340e9e9d.tar.gz
perlweeklychallenge-club-d90ac3c7ece6997c41d3351a69f6a25d340e9e9d.tar.bz2
perlweeklychallenge-club-d90ac3c7ece6997c41d3351a69f6a25d340e9e9d.zip
Add solution of ch-122-1 in c++ and add stdlib in c solution
-rw-r--r--challenge-122/karishma/C/ch-1.c30
-rwxr-xr-xchallenge-122/karishma/c++/ch1bin0 -> 17320 bytes
-rw-r--r--challenge-122/karishma/c++/ch1.cpp33
3 files changed, 63 insertions, 0 deletions
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 <stdio.h>
+#include<stdlib.h>
+
+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
--- /dev/null
+++ b/challenge-122/karishma/c++/ch1
Binary files 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 <iostream>
+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<<endl;
+ // }
+ int sum = 0;
+ for (int j = 1; j <= n; j++) {
+ sum += ptr[j-1];
+ int k= sum/j;
+ cout<<k;
+ cout<<endl;
+ }
+ cout<<endl;
+
+ return 0;
+} \ No newline at end of file