From 2844c3556f825b336ef3dd5e34a0d8c14e3c0eea Mon Sep 17 00:00:00 2001 From: ashkan hfz Date: Sat, 16 Apr 2022 14:41:56 +0430 Subject: [PATCH] ashkan edit --- 1.cpp | 15 ++++++--------- 2.cpp | 23 ++++++++++++----------- 3.cpp | 2 +- 4.cpp | 8 +++++--- 5.cpp | 8 +++++--- 6.cpp | 1 + 7.cpp | 3 ++- 8.cpp | 14 +++++++------- 8 files changed, 39 insertions(+), 35 deletions(-) diff --git a/1.cpp b/1.cpp index fedde2c..65ebffc 100644 --- a/1.cpp +++ b/1.cpp @@ -1,7 +1,6 @@ #include #include #include - using namespace std; long long *b; @@ -13,11 +12,11 @@ long long int factorial(int n) long long int *producingTheFactorialFractions() { - long long b[10]; + 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] += (long long int)pow(factorial(10), 2.0) / (i + 1); } return b; } @@ -26,7 +25,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 +42,6 @@ int main() } delete a; - cout<<"hello"; - cout<<"Bye"; - - + cout << "hello\n"; + cout << "Bye"; } \ No newline at end of file diff --git a/2.cpp b/2.cpp index 6a27746..51999fb 100644 --- a/2.cpp +++ b/2.cpp @@ -4,23 +4,24 @@ 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..5855d07 100644 --- a/3.cpp +++ b/3.cpp @@ -97,7 +97,7 @@ int average() return sum / count; } -void main() +int main() { int cmd; long long int x; diff --git a/4.cpp b/4.cpp index a9a32f2..7676332 100644 --- a/4.cpp +++ b/4.cpp @@ -1,9 +1,11 @@ -#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..00fd8d0 100644 --- a/6.cpp +++ b/6.cpp @@ -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..d6fb744 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 +} +// 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