diff --git a/1.cpp b/1.cpp index fedde2c..e31276e 100644 --- a/1.cpp +++ b/1.cpp @@ -4,29 +4,33 @@ using namespace std; -long long *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() { - long long b[10]; + // memory allocation + b = new long double[10]; - for (int i = 10; i >= 0; i--) + // 10 -> 9 + for (int i = 9; i >= 0; i--) { - b[i] += (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--) { - if (a[i] = 0) + // equality oprator + if (a[i] == 0) cout << "Zero Found" << endl; } } @@ -34,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++) @@ -43,8 +47,20 @@ int main() } delete a; - cout<<"hello"; - cout<<"Bye"; + 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 diff --git a/2.cpp b/2.cpp index 6a27746..25a4039 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; // intial value = 0 + for (int i = 0; i < arrLength; i++) //< arrlength not eqaul + { + 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; + } + } + } 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/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 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 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; } 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 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 }