diff --git a/1.cpp b/1.cpp index fedde2c..01f9137 100644 --- a/1.cpp +++ b/1.cpp @@ -4,29 +4,29 @@ using namespace std; -long long *b; +long long* b; long long int factorial(int n) { return (n == 1 || n == 0) ? 1 : factorial(n - 1) * n; } -long long int *producingTheFactorialFractions() +long long int* producingTheFactorialFractions() { - long long b[10]; + long long b[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); } return b; } -void checkZeros(long long *a) +void checkZeros(long long* a) { for (int i = 9; i >= 0; i--) { - if (a[i] = 0) + if (a[i] == 0) cout << "Zero Found" << endl; } } @@ -34,7 +34,7 @@ void checkZeros(long long *a) int main() { - long long int *a; + long long int* a; a = producingTheFactorialFractions(); checkZeros(a); for (int i = 0; i < 10; i++) @@ -43,8 +43,8 @@ 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..5b0dfb4 100644 --- a/2.cpp +++ b/2.cpp @@ -5,11 +5,11 @@ 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 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; } @@ -23,5 +23,5 @@ int main() { }; char findIt; cin >> findIt; - cout << countAllSpecificChars(sArr, 4, findIt); + cout << countAllSpecificChars(sArr, 4,findIt); } \ No newline at end of file diff --git a/3.cpp b/3.cpp index 77eb722..72b3894 100644 --- a/3.cpp +++ b/3.cpp @@ -1,9 +1,13 @@ #include #include +#pragma warning(disable:4996) #define MAX_SIZE 200 int arr[MAX_SIZE]; -typedef struct alfa * alfaptr; +//do ta countash moshkel dasht + + +typedef struct alfa* alfaptr; struct alfa { long long x; @@ -45,7 +49,7 @@ void search(int x) printf("ERROR2"); break; } - node = node->next; + node = node->next; } void rpop() {//pop last element @@ -66,9 +70,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 +92,8 @@ int average() { alfaptr node = front; - int sum = 0, count; + int sum = 0; + int count = 0; while (node) { sum += node->x; count++; @@ -97,7 +102,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..b20ce46 100644 --- a/4.cpp +++ b/4.cpp @@ -2,8 +2,9 @@ int main() { float arr[5] = { 12.5, 10.0, 13.5, 90.5, 0.5 }; - float *ptr1 = &arr[0]; - float *ptr2 = ptr1 + 3; + float* ptr1 = &arr[0]; + float* ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; + //78.0000 = 90.5-12.5 } \ No newline at end of file diff --git a/5.cpp b/5.cpp index 1be3d10..a3f523b 100644 --- a/5.cpp +++ b/5.cpp @@ -5,6 +5,8 @@ int main() int *ptr1 = arr; int *ptr2 = arr + 5; printf("%d\n", (*ptr2 - *ptr1)); + //50 printf("%c", (char)(*ptr2 - *ptr1)); + //chizi ke code ascci an 50 ast ro print mikone return 0; } \ No newline at end of file diff --git a/6.cpp b/6.cpp index f8b3141..ddc0ac3 100644 --- a/6.cpp +++ b/6.cpp @@ -2,8 +2,15 @@ int main() { int a; - char *x; - x = (char *)&a; + char* x; + // alan char* x be adress a ehshare mikone va ba x[0] byte avalesho be 1 tabdil mikone ke baes mishe addademon avaz she + + //summary: the code is gibberish and the C language doesn't define what this program will do. + //It may crash, print any value or print no value at all. + //Pondering about why it behaves in a certain way ***isn't meaningful practice.*** Instead focus on learning how to avoid undefined behavior bugs. + + //inam ye shakhsi to stackoverflow neveshte bood + x = (char*)&a; a = 512; x[0] = 1; printf("%d\n", a); diff --git a/7.cpp b/7.cpp index 7b065a0..0f918aa 100644 --- a/7.cpp +++ b/7.cpp @@ -2,8 +2,11 @@ int main() { int arr[] = { 1, 2, 3, 4, 5 }; - int *p = arr; - ++*p; + int* p = arr; + // ++* p meghda *p ra ye dane ziad mikone + ++* p; + //printf("%d", *p) tebgh bala age *p ra print konim 1 yedone ziad shode va addad 2 baraye me print mishe + // p+= 2 be baes mishe p 2 ta khone dar array jelo bere va adda 3 ke to khoney sevome ro print begire p += 2; printf("%d", *p); return 0; diff --git a/8.cpp b/8.cpp index ac3d613..5b04bbb 100644 --- a/8.cpp +++ b/8.cpp @@ -8,6 +8,6 @@ int main() { 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 }