From 69b47659f5afb0e16f8d236851f9e3d773b1e3a0 Mon Sep 17 00:00:00 2001 From: nosi Date: Wed, 17 Mar 2021 21:47:18 +0330 Subject: [PATCH 1/7] code debug --- 1.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/1.cpp b/1.cpp index fedde2c..e46838a 100644 --- a/1.cpp +++ b/1.cpp @@ -4,8 +4,6 @@ using namespace std; -long long *b; - long long int factorial(int n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; @@ -15,7 +13,7 @@ long long int *producingTheFactorialFractions() { long long b[10]; - for (int i = 10; i >= 0; i--) + for (int i = 9; i >= 0; i--) { b[i] += (int)pow(factorial(10), 2.0) / (i + 1); } @@ -35,10 +33,11 @@ int main() { long long int *a; - a = producingTheFactorialFractions(); + checkZeros(a); for (int i = 0; i < 10; i++) { + a = producingTheFactorialFractions(); cout << a[i] << endl; } delete a; From 36881eb94522138eb82f18dd9b137e0589b4e104 Mon Sep 17 00:00:00 2001 From: nosi Date: Wed, 17 Mar 2021 21:52:23 +0330 Subject: [PATCH 2/7] debug code 2 --- 2.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/2.cpp b/2.cpp index 6a27746..58e302a 100644 --- a/2.cpp +++ b/2.cpp @@ -5,11 +5,11 @@ using namespace std; // count all the specific char in the whole array of strings int countAllSpecificChars(string sArr[], int arrLength, char specificChar) { - int count; - for (int i = 0; i <= arrLength; ++i) - for (int j = 0; j <= sArr[i].size(); ++j) + int count=0; + for (int i = 0; i < arrLength; ++i) + for (int j = 0; j < sArr[i].size(); ++j) // if the jth char of the string is the specific char - if (sArr[i][j] = specificChar) + if (sArr[i][j] == specificChar) count++; return count; } From cb81c8c925665ac9b5bc50039a5eb9f1e1a1c3ae Mon Sep 17 00:00:00 2001 From: nosi Date: Thu, 18 Mar 2021 18:29:54 +0330 Subject: [PATCH 3/7] debug 3 --- 3.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 20 deletions(-) diff --git a/3.cpp b/3.cpp index 77eb722..a53bc59 100644 --- a/3.cpp +++ b/3.cpp @@ -1,9 +1,9 @@ #include #include #define MAX_SIZE 200 -int arr[MAX_SIZE]; +long long arr[MAX_SIZE]; -typedef struct alfa * alfaptr; +typedef struct alfa* alfaptr; struct alfa { long long x; @@ -15,11 +15,25 @@ void push(int x) alfaptr node; node = (alfaptr)malloc(sizeof(struct alfa)); node->x = x; - if (!front) + node->next = NULL; + + if (!front) { front = node; + + rear = front; + rear->next = NULL; + } + + + + else { + //printf("sala,%lld", rear->x); rear->next = node; rear = node; + + rear->next = NULL; + //printf("sala,%lld", rear->x); } } @@ -36,16 +50,22 @@ void pop() } void search(int x) { + int y = 0; alfaptr node = front; int counter = 0; - while (node) - if (node->x == x) + while (node) { + if (node->x == x) { printf("%d", counter); - else { - printf("ERROR2"); - break; + y = 1; } node = node->next; + } + if (y == 0) { + + printf("eroe 2"); + + } + } void rpop() {//pop last element @@ -58,25 +78,49 @@ void rpop() {//pop last element void set() { + int j = 0; + long long m; + alfaptr node = front; - for (int i = 0; i < MAX_SIZE && node; i++, node = node->next) + + + + for (int i = 0; node != NULL; i++, node = node->next) { arr[i] = node->x; + + printf("%lld ", arr[i]); + + } + } int size() { alfaptr node = front; - int count; - while (node) - count++;node = node->next; + int count = 0; + while (node) { + count++; + node = node->next; + // printf("%lld", node); + } + return count; } void show() { - if (!front) { - for (int i = 0; i < MAX_SIZE; i++) - printf("%d ", arr[i]); + if (front) { + alfaptr node = front; + + for (int i = 0; node != NULL; i++) { + + + printf("%lld ", arr[i]); + + node = node->next; + } + + } else { @@ -88,8 +132,9 @@ int average() { alfaptr node = front; - int sum = 0, count; - while (node) { + long long sum = 0; + int count = 0; + while (node != NULL) { sum += node->x; count++; node = node->next; @@ -103,11 +148,11 @@ void main() long long int x; while (true) { - scanf("%d", &cmd); + scanf_s("%d", &cmd); switch (cmd) { case 1://push - scanf("%lld", &x); + scanf_s("%lld", &x); push(x); break; case 2://pop @@ -117,7 +162,7 @@ void main() rpop(); break; case 4://search - scanf("%lld", &x); + scanf_s("%lld", &x); search(x); break; case 5://set From cf27b5b4050a640ea5ed2db85b0868d525c495e2 Mon Sep 17 00:00:00 2001 From: nosi Date: Thu, 18 Mar 2021 18:34:49 +0330 Subject: [PATCH 4/7] addres aray copy shod dar pointer va ekhtlaf do ar[0]-ar[3] --- 4.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/4.cpp b/4.cpp index a9a32f2..3a0620e 100644 --- a/4.cpp +++ b/4.cpp @@ -6,4 +6,5 @@ int main() float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file +} +// addres aray copy shod dar pointer; \ No newline at end of file From 2050e370eb6937aab8ac97b00066df7439edb176 Mon Sep 17 00:00:00 2001 From: nosi Date: Thu, 18 Mar 2021 18:57:58 +0330 Subject: [PATCH 5/7] dar khat aval akhtelaf ar[0]-ar[5] va dar khat dovom ekhtelaf adrese khane ha --- 5.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/5.cpp b/5.cpp index 1be3d10..b53626b 100644 --- a/5.cpp +++ b/5.cpp @@ -7,4 +7,5 @@ int main() printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); return 0; -} \ No newline at end of file +} +//dar khat aval akhtelaf ar[0]-ar[5] va dar khat dovom ekhtelaf adrese khane ha \ No newline at end of file From 1f03c11a6d1ced67add653b7c0d53f14f001f5b3 Mon Sep 17 00:00:00 2001 From: nosi Date: Thu, 18 Mar 2021 19:07:30 +0330 Subject: [PATCH 6/7] add rese a ro be char constant kar bad barabare x gharar dad --- 6.cpp | 1 + 7.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/6.cpp b/6.cpp index f8b3141..c325122 100644 --- a/6.cpp +++ b/6.cpp @@ -9,3 +9,4 @@ int main() printf("%d\n", a); return 0; } +// add rese a ro be char constant kar bad barabare x gharar dad \ No newline at end of file diff --git a/7.cpp b/7.cpp index 7b065a0..e6622f4 100644 --- a/7.cpp +++ b/7.cpp @@ -7,4 +7,5 @@ int main() p += 2; printf("%d", *p); return 0; -} \ No newline at end of file +} +// meghdar arr[4] \ No newline at end of file From 824e88507fa52b9eca1a6a8bf4c2cf4c0890d0e9 Mon Sep 17 00:00:00 2001 From: nosi Date: Thu, 18 Mar 2021 19:10:33 +0330 Subject: [PATCH 7/7] /khat aval harf w va dar dowoi harf y --- 8.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/8.cpp b/8.cpp index d851551..f27a48b 100644 --- a/8.cpp +++ b/8.cpp @@ -8,3 +8,4 @@ int main() { printf("%c%c ", *f(str), *(f(str) + 1)); printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1)); } +//khat aval harf w va dar dowoi harf y \ No newline at end of file