From f866c4d7c32183f14cc4f715e0108bfa247cff57 Mon Sep 17 00:00:00 2001 From: Ali Berenjkoub Date: Fri, 19 Mar 2021 14:45:05 +0330 Subject: [PATCH] debugg --- 1.cpp | 15 ++++++--------- 2.cpp | 9 +++++---- 3.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 4.cpp | 6 +++++- 5.cpp | 6 +++++- 6.cpp | 2 ++ 7.cpp | 4 +++- 8.cpp | 2 ++ 8 files changed, 79 insertions(+), 27 deletions(-) diff --git a/1.cpp b/1.cpp index fedde2c..6ee6ca5 100644 --- a/1.cpp +++ b/1.cpp @@ -13,12 +13,13 @@ long long int factorial(int n) long long int *producingTheFactorialFractions() { - long long b[10]; + long long *b = new long long[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); + b[i] += pow(factorial(10), 2.0) / (i + 1); } + return b; } @@ -26,7 +27,7 @@ void checkZeros(long long *a) { for (int i = 9; i >= 0; i--) { - if (a[i] = 0) + if (a[i] == 0) cout << "Zero Found" << endl; } } @@ -43,8 +44,4 @@ int main() } delete a; - cout<<"hello"; - cout<<"Bye"; - - -} \ No newline at end of file +} diff --git a/2.cpp b/2.cpp index 6a27746..74ae1b4 100644 --- a/2.cpp +++ b/2.cpp @@ -1,15 +1,16 @@ #include #include + 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; } diff --git a/3.cpp b/3.cpp index 77eb722..b096031 100644 --- a/3.cpp +++ b/3.cpp @@ -16,11 +16,16 @@ void push(int x) node = (alfaptr)malloc(sizeof(struct alfa)); node->x = x; if (!front) + { front = node; + rear = front; + } else { rear->next = node; rear = node; } + + node->next = NULL; } void pop() @@ -31,6 +36,7 @@ void pop() else { node = front->next; + free(front); front = node; } } @@ -39,25 +45,41 @@ void search(int x) alfaptr node = front; int counter = 0; while (node) + { if (node->x == x) - printf("%d", counter); - else { - printf("ERROR2"); - break; - } + counter ++; + node = node->next; + } + + printf("%d", counter); } void rpop() {//pop last element + if(!front) + return; + alfaptr node = front; - while (node) + if(node != rear) + { + while (node->next != rear) node = node->next; + free(rear); rear = node; + rear->next = NULL; + } + + free(rear); + front = NULL; + rear = NULL; } void set() { + if(!front) + return; + alfaptr node = front; for (int i = 0; i < MAX_SIZE && node; i++, node = node->next) arr[i] = node->x; @@ -66,9 +88,11 @@ void set() int size() { alfaptr node = front; - int count; + int count = 0; while (node) + { count++;node = node->next; + } return count; } @@ -80,15 +104,22 @@ void show() } else { - printf("ERROR3"); + alfaptr node = front; + while(node) + { + printf("%lld ", node->x); + node = node->next; + } } } int average() { + if(!front) + return 0; alfaptr node = front; - int sum = 0, count; + int sum = 0, count = 0; while (node) { sum += node->x; count++; @@ -97,7 +128,7 @@ int average() return sum / count; } -void main() +int main() { int cmd; long long int x; @@ -132,5 +163,14 @@ void main() case 10: exit(0); } + + printf("\n"); } -} \ No newline at end of file + + + +while(size()) + pop(); + +return 0; +} diff --git a/4.cpp b/4.cpp index a9a32f2..20a9a92 100644 --- a/4.cpp +++ b/4.cpp @@ -3,7 +3,11 @@ int main() { float arr[5] = { 12.5, 10.0, 13.5, 90.5, 0.5 }; float *ptr1 = &arr[0]; + printf("%f\n",*ptr1);//ezafe shode float *ptr2 = ptr1 + 3; + printf("%f\n",*ptr2);//ezafe shode printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file +} + +//Moshkeli nadare diff --git a/5.cpp b/5.cpp index 1be3d10..de4ca02 100644 --- a/5.cpp +++ b/5.cpp @@ -3,8 +3,12 @@ int main() { int arr[] = { 10, 20, 30, 40, 50, 60 }; int *ptr1 = arr; + printf("%d",*ptr1);//ezafe shode int *ptr2 = arr + 5; + printf("%d",*ptr2);//ezafe shode printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); return 0; -} \ No newline at end of file +} + +//Moshkeli nadare diff --git a/6.cpp b/6.cpp index f8b3141..8ad661e 100644 --- a/6.cpp +++ b/6.cpp @@ -9,3 +9,5 @@ int main() printf("%d\n", a); return 0; } +//out put:513 +//Moshkeli nadare \ No newline at end of file diff --git a/7.cpp b/7.cpp index 7b065a0..40ddebe 100644 --- a/7.cpp +++ b/7.cpp @@ -7,4 +7,6 @@ int main() p += 2; printf("%d", *p); return 0; -} \ No newline at end of file +} +//out put: 3 +//Moshkeli nadare \ No newline at end of file diff --git a/8.cpp b/8.cpp index d851551..9dbf84f 100644 --- a/8.cpp +++ b/8.cpp @@ -8,3 +8,5 @@ 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)); } +//out put: Be WooW +//Moshkeli nadare \ No newline at end of file