From d83742609d2e4e53d2e2f0a25ae376e1791ab8fe Mon Sep 17 00:00:00 2001 From: Hamidreza Ataei <3ataei@gmail.com> Date: Fri, 8 Apr 2022 01:36:45 +0430 Subject: [PATCH] bug fixed --- 1.cpp | 14 ++++++-------- 2.cpp | 27 ++++++++++++++++----------- 3.cpp | 13 +++++++++---- 4.cpp | 7 ++++--- 5.cpp | 8 +++++--- 6.cpp | 3 ++- 7.cpp | 7 ++++--- 8.cpp | 14 +++++++------- 8 files changed, 53 insertions(+), 40 deletions(-) diff --git a/1.cpp b/1.cpp index fedde2c..547dbad 100644 --- a/1.cpp +++ b/1.cpp @@ -13,20 +13,20 @@ long long int factorial(int n) long long int *producingTheFactorialFractions() { - long long b[10]; + long long int *b = new long long int[10]; for (int i = 10; i >= 0; i--) { - b[i] += (int)pow(factorial(10), 2.0) / (i + 1); + b[i] = pow(factorial(10), 2) / (i + 1); } return b; } void checkZeros(long long *a) { - for (int i = 9; i >= 0; i--) + for (int i = 10; i >= 0; i--) { - if (a[i] = 0) + if (a[i] == 0) cout << "Zero Found" << endl; } } @@ -43,8 +43,6 @@ int main() } delete a; - cout<<"hello"; - cout<<"Bye"; - - + cout << "hello"; + cout << "Bye"; } \ No newline at end of file diff --git a/2.cpp b/2.cpp index 6a27746..9bb09f9 100644 --- a/2.cpp +++ b/2.cpp @@ -4,23 +4,28 @@ 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 countAllSpecificChars(string sArr[], int arrLength, char specificChar) +{ + 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; } -int main() { +int main() +{ string sArr[4] = { - "I am", - "in", - "ap", - "class" - }; + "I am", + "in", + "ap", + "class"}; char findIt; cin >> findIt; cout << countAllSpecificChars(sArr, 4, findIt); diff --git a/3.cpp b/3.cpp index 77eb722..991eab3 100644 --- a/3.cpp +++ b/3.cpp @@ -39,6 +39,7 @@ void search(int x) alfaptr node = front; int counter = 0; while (node) + { if (node->x == x) printf("%d", counter); else { @@ -46,6 +47,7 @@ void search(int x) break; } node = node->next; + } } void rpop() {//pop last element @@ -68,13 +70,16 @@ int size() alfaptr node = front; int count; while (node) - count++;node = node->next; + { + count++; + node = node->next; + } return count; } void show() { - if (!front) { + if (front) { for (int i = 0; i < MAX_SIZE; i++) printf("%d ", arr[i]); } @@ -97,7 +102,7 @@ int average() return sum / count; } -void main() +int main() { int cmd; long long int x; @@ -130,7 +135,7 @@ void main() printf("%d", size()); break; case 10: - exit(0); + return 0; } } } \ No newline at end of file diff --git a/4.cpp b/4.cpp index a9a32f2..ecaaa70 100644 --- a/4.cpp +++ b/4.cpp @@ -1,9 +1,10 @@ -#include +#include int main() { - float arr[5] = { 12.5, 10.0, 13.5, 90.5, 0.5 }; + float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5}; float *ptr1 = &arr[0]; float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file +} +// 78.000000 \ No newline at end of file diff --git a/5.cpp b/5.cpp index 1be3d10..651d504 100644 --- a/5.cpp +++ b/5.cpp @@ -1,10 +1,12 @@ -#include +#include int main() { - int arr[] = { 10, 20, 30, 40, 50, 60 }; + int arr[] = {10, 20, 30, 40, 50, 60}; int *ptr1 = arr; int *ptr2 = arr + 5; printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); return 0; -} \ No newline at end of file +} +// 50 +// 2 \ No newline at end of file diff --git a/6.cpp b/6.cpp index f8b3141..a05636b 100644 --- a/6.cpp +++ b/6.cpp @@ -1,4 +1,4 @@ -#include +#include int main() { int a; @@ -9,3 +9,4 @@ int main() printf("%d\n", a); return 0; } +// 513 \ No newline at end of file diff --git a/7.cpp b/7.cpp index 7b065a0..b606175 100644 --- a/7.cpp +++ b/7.cpp @@ -1,10 +1,11 @@ -#include +#include int main() { - int arr[] = { 1, 2, 3, 4, 5 }; + int arr[] = {1, 2, 3, 4, 5}; int *p = arr; ++*p; p += 2; printf("%d", *p); return 0; -} \ No newline at end of file +} +// 3 \ No newline at end of file diff --git a/8.cpp b/8.cpp index ac3d613..7afb4b8 100644 --- a/8.cpp +++ b/8.cpp @@ -1,13 +1,13 @@ -#include -const char * f(const char **p) { +#include +const char *f(const char **p) +{ auto q = (p + sizeof(char))[1]; return q; } -int main() { - const char * str[] = { "Wish","You","Best",":D" }; +int main() +{ + const char *str[] = {"Wish", "You", "Best", ":D"}; 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)); - - - } +// Be WooW \ No newline at end of file