From 5d70a189e95f0f911b1936ee3e3e09fa27c3b723 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Fri, 8 Apr 2022 17:41:26 +0430 Subject: [PATCH 01/10] Fixed --- 1.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/1.cpp b/1.cpp index fedde2c..45430b4 100644 --- a/1.cpp +++ b/1.cpp @@ -4,7 +4,7 @@ using namespace std; -long long *b; +long long int *b; long long int factorial(int n) { @@ -13,11 +13,11 @@ long long int factorial(int n) long long int *producingTheFactorialFractions() { - long long b[10]; + b = new long long int[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 +26,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 +43,6 @@ int main() } delete a; - cout<<"hello"; - cout<<"Bye"; - - + cout << "hello"; + cout << "Bye"; } \ No newline at end of file From d84e4e8ef72f391178c57f265239dc874caf62c8 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Fri, 8 Apr 2022 17:53:34 +0430 Subject: [PATCH 02/10] Fixed --- 2.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/2.cpp b/2.cpp index 6a27746..d0a4669 100644 --- a/2.cpp +++ b/2.cpp @@ -4,23 +4,29 @@ 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) - // if the jth char of the string is the specific char - if (sArr[i][j] = specificChar) - count++; +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) + { + count += 1; + } + } + } 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); From 0130447fbc184453053f9d5f45d00f7f05a9b745 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Mon, 18 Apr 2022 23:27:56 +0430 Subject: [PATCH 03/10] Completed --- 1.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/1.cpp b/1.cpp index 45430b4..32cd5de 100644 --- a/1.cpp +++ b/1.cpp @@ -4,7 +4,7 @@ using namespace std; -long long int *b; +long long int * b; long long int factorial(int n) { @@ -13,11 +13,13 @@ long long int factorial(int n) long long int *producingTheFactorialFractions() { + //memory allocation b = new long long int[10]; - + //10 -> 9 for (int i = 9; i >= 0; i--) { - b[i] = (pow(factorial(10), 2.0) / (i + 1)); + //equal + b[i] = (long long int)(pow(factorial(10), 2.0) / (i + 1)); } return b; } @@ -26,6 +28,7 @@ void checkZeros(long long *a) { for (int i = 9; i >= 0; i--) { + //equality oprator if (a[i] == 0) cout << "Zero Found" << endl; } From 6351a8cfe28b6855cac384b1763b1a0b69de9d03 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Mon, 18 Apr 2022 23:36:34 +0430 Subject: [PATCH 04/10] factorial and then pow --- 1.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/1.cpp b/1.cpp index 32cd5de..e31276e 100644 --- a/1.cpp +++ b/1.cpp @@ -4,31 +4,32 @@ using namespace std; -long long int * b; +long double *b; long long int factorial(int n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; } -long long int *producingTheFactorialFractions() +long double *producingTheFactorialFractions() { - //memory allocation - b = new long long int[10]; - //10 -> 9 + // memory allocation + b = new long double[10]; + + // 10 -> 9 for (int i = 9; i >= 0; i--) { - //equal - b[i] = (long long int)(pow(factorial(10), 2.0) / (i + 1)); + // equal + 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--) { - //equality oprator + // equality oprator if (a[i] == 0) cout << "Zero Found" << endl; } @@ -37,7 +38,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++) @@ -48,4 +49,18 @@ int main() cout << "hello"; cout << "Bye"; -} \ No newline at end of file +} + + +//javab +// 1.31682e+013 +// 6.58409e+012 +// 4.3894e+012 +// 3.29205e+012 +// 2.63364e+012 +// 2.1947e+012 +// 1.88117e+012 +// 1.64602e+012 +// 1.46313e+012 +// 1.31682e+012 +// helloBye \ No newline at end of file From 5fb98bcc992fd88a655aea00ffd58e1822e4d262 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Mon, 18 Apr 2022 23:41:23 +0430 Subject: [PATCH 05/10] finds the given char's number in arr --- 2.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/2.cpp b/2.cpp index d0a4669..25a4039 100644 --- a/2.cpp +++ b/2.cpp @@ -6,12 +6,12 @@ using namespace std; // count all the specific char in the whole array of strings int countAllSpecificChars(string sArr[], int arrLength, char specificChar) { - int count = 0; - for (int i = 0; i < arrLength; i++) + int count = 0; // intial value = 0 + for (int i = 0; i < arrLength; i++) //< arrlength not eqaul { - 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) + for (int j = 0; j < sArr[i].size(); j++) //< arrlength not eqaul + { // if the jth char of the string is the specific char + if (sArr[i][j] == specificChar) // equality oprator { count += 1; } From 51407077f209145e762f9154467a3b7aa9580975 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Tue, 19 Apr 2022 22:48:36 +0430 Subject: [PATCH 06/10] Be WooW --- 8.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/8.cpp b/8.cpp index ac3d613..3d6a15f 100644 --- a/8.cpp +++ b/8.cpp @@ -1,13 +1,12 @@ -#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)); - - - + printf("%c%c%c%c\n", **str, *(*(str + 1) + 1), *((str + 2)[-1] + 1), **&*(&str[-1] + 1)); // Be WooW } From 1ae250e576ab2849ad59431e633448cf0a6ef223 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Tue, 19 Apr 2022 22:49:18 +0430 Subject: [PATCH 07/10] 3 --- 7.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/7.cpp b/7.cpp index 7b065a0..d609561 100644 --- a/7.cpp +++ b/7.cpp @@ -2,9 +2,9 @@ int main() { int arr[] = { 1, 2, 3, 4, 5 }; - int *p = arr; - ++*p; - p += 2; - printf("%d", *p); + int *p = arr; //p = 1 + ++*p; //p = 2 + p += 2; //p = 3 + printf("%d", *p); return 0; } \ No newline at end of file From 67dd3e1e82ca84cf98c2325c28617004e3c97a54 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Tue, 19 Apr 2022 22:49:48 +0430 Subject: [PATCH 08/10] 513 --- 6.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/6.cpp b/6.cpp index f8b3141..cd5c1c3 100644 --- a/6.cpp +++ b/6.cpp @@ -6,6 +6,6 @@ int main() x = (char *)&a; a = 512; x[0] = 1; - printf("%d\n", a); + printf("%d\n", a); //513 return 0; } From ebeee1d469f3aff74f69f204e3a2ac6d80b25f23 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Tue, 19 Apr 2022 22:50:22 +0430 Subject: [PATCH 09/10] 50 - 2 --- 5.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/5.cpp b/5.cpp index 1be3d10..682b5de 100644 --- a/5.cpp +++ b/5.cpp @@ -4,7 +4,9 @@ int main() 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)); + printf("%d\n", (*ptr2 - *ptr1)); //60-10 + printf("%c", (char)(*ptr2 - *ptr1)); //عدد اسکی 50 return 0; -} \ No newline at end of file +} +//50 +//2 From fd7cf26064ed28829df2ad6a5d29abc52d06ca60 Mon Sep 17 00:00:00 2001 From: Alir3zaRaisi Date: Tue, 19 Apr 2022 22:50:57 +0430 Subject: [PATCH 10/10] 78.000000 --- 4.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/4.cpp b/4.cpp index a9a32f2..85ac0d8 100644 --- a/4.cpp +++ b/4.cpp @@ -6,4 +6,7 @@ int main() float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file +} + + +//78.000000 90.5 - 12.5 \ No newline at end of file