From 54405427512bcdde6efead9b6dcc98f16302cf8f Mon Sep 17 00:00:00 2001 From: mhasan Date: Tue, 19 Apr 2022 02:12:49 +0430 Subject: [PATCH] fix bugs --- 1.cpp | 40 +++++++++++++++++++++++++++------------- 2.cpp | 11 +++++++---- 3.cpp | 13 +++++++------ 4.cpp | 1 + 5.cpp | 2 ++ 6.cpp | 1 + 7.cpp | 1 + 8.cpp | 2 +- 8 files changed, 47 insertions(+), 24 deletions(-) diff --git a/1.cpp b/1.cpp index fedde2c..c3025f3 100644 --- a/1.cpp +++ b/1.cpp @@ -4,29 +4,31 @@ using namespace std; -long long *b; +long double* b; -long long int factorial(int n) +long double factorial(int n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; } -long long int *producingTheFactorialFractions() +long double* producingTheFactorialFractions() { - long long b[10]; + //memory allocation for b + b = new long double[10]; - for (int i = 10; i >= 0; i--) + //i must be 9 + for (int i = 9; i >= 0; i--) { - b[i] += (int)pow(factorial(10), 2.0) / (i + 1); + b[i] = (long double)pow(factorial(10), 2.0) / (i + 1); } return b; } -void checkZeros(long long *a) +void checkZeros(long double* a) { for (int i = 9; i >= 0; i--) - { - if (a[i] = 0) + {//2 ta mosavy + if (a[i] == 0) cout << "Zero Found" << endl; } } @@ -34,7 +36,7 @@ void checkZeros(long long *a) int main() { - long long int *a; + long double* a; a = producingTheFactorialFractions(); checkZeros(a); for (int i = 0; i < 10; i++) @@ -43,8 +45,20 @@ int main() } delete a; - cout<<"hello"; - cout<<"Bye"; - + cout << "hello"; + cout << "Bye"; + /* + 1.31682e+13 + 6.58409e+12 + 4.3894e+12 + 3.29205e+12 + 2.63364e+12 + 2.1947e+12 + 1.88117e+12 + 1.64602e+12 + 1.46313e+12 + 1.31682e+12 + helloBye + */ } \ No newline at end of file diff --git a/2.cpp b/2.cpp index 6a27746..d3bc571 100644 --- a/2.cpp +++ b/2.cpp @@ -5,11 +5,14 @@ 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) + //intialized count + int count = 0; + //i++ + for (int i = 0; i < arrLength; i++) + //j++ + 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..9bda1ef 100644 --- a/3.cpp +++ b/3.cpp @@ -3,10 +3,11 @@ #define MAX_SIZE 200 int arr[MAX_SIZE]; -typedef struct alfa * alfaptr; +typedef struct alfa* alfaptr; struct alfa { - long long x; + //long long int + long long int x; alfaptr next; }; alfaptr rear = NULL, front = NULL; @@ -45,7 +46,7 @@ void search(int x) printf("ERROR2"); break; } - node = node->next; + node = node->next; } void rpop() {//pop last element @@ -66,9 +67,9 @@ void set() int size() { alfaptr node = front; - int count; + int count = 0; while (node) - count++;node = node->next; + count++; node = node->next; return count; } @@ -88,7 +89,7 @@ int average() { alfaptr node = front; - int sum = 0, count; + int sum = 0, count = 0; while (node) { sum += node->x; count++; diff --git a/4.cpp b/4.cpp index a9a32f2..0856a56 100644 --- a/4.cpp +++ b/4.cpp @@ -6,4 +6,5 @@ int main() float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; + //78.000000 } \ No newline at end of file diff --git a/5.cpp b/5.cpp index 1be3d10..fe8b140 100644 --- a/5.cpp +++ b/5.cpp @@ -7,4 +7,6 @@ int main() printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); return 0; + //50 + //2 } \ No newline at end of file diff --git a/6.cpp b/6.cpp index f8b3141..cfc0cff 100644 --- a/6.cpp +++ b/6.cpp @@ -8,4 +8,5 @@ int main() x[0] = 1; printf("%d\n", a); return 0; + //513 } diff --git a/7.cpp b/7.cpp index 7b065a0..3d9ddbe 100644 --- a/7.cpp +++ b/7.cpp @@ -7,4 +7,5 @@ int main() p += 2; printf("%d", *p); return 0; + //3 } \ No newline at end of file diff --git a/8.cpp b/8.cpp index ac3d613..01679bb 100644 --- a/8.cpp +++ b/8.cpp @@ -9,5 +9,5 @@ int main() { printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1)); - + //Be WooW }