diff --git a/1.cpp b/1.cpp index fedde2c..84d8580 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,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];//assigning memory. - for (int i = 10; i >= 0; i--) + for (int i = 9; i >= 0; i--)//changing i. { - b[i] += (int)pow(factorial(10), 2.0) / (i + 1); + b[i] = (long long int)pow(factorial(10), 2.0) / (i + 1);//changing int to long long int. } return b; } -void checkZeros(long long *a) +void checkZeros(long long int* a)//changing long long to long long int. { for (int i = 9; i >= 0; i--) { - if (a[i] = 0) + if (a[i] == 0)//changing = to ==. cout << "Zero Found" << endl; } } @@ -34,7 +34,7 @@ void checkZeros(long long *a) int main() { - long long int *a; + long long int *a = new long long int[10];//new assigning memory. a = producingTheFactorialFractions(); checkZeros(a); for (int i = 0; i < 10; i++) @@ -43,8 +43,8 @@ int main() } delete a; - cout<<"hello"; + cout<<"hello" << endl; cout<<"Bye"; -} \ No newline at end of file +} diff --git a/2.cpp b/2.cpp index 6a27746..71c73e9 100644 --- a/2.cpp +++ b/2.cpp @@ -6,10 +6,10 @@ 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) + for (int i = 0; i < arrLength; ++i)// chabging <= to <. + for (int j = 0; j < sArr[i].size(); ++j)//changing <= to <. // if the jth char of the string is the specific char - if (sArr[i][j] = specificChar) + if (sArr[i][j] == specificChar)//changing = to ==. count++; return count; } @@ -24,4 +24,4 @@ int main() { char findIt; cin >> findIt; cout << countAllSpecificChars(sArr, 4, findIt); -} \ No newline at end of file +} diff --git a/3.cpp b/3.cpp index 77eb722..9a8be0e 100644 --- a/3.cpp +++ b/3.cpp @@ -1,6 +1,8 @@ #include #include #define MAX_SIZE 200 +using namespace std; + int arr[MAX_SIZE]; typedef struct alfa * alfaptr; @@ -15,9 +17,16 @@ void push(int x) alfaptr node; node = (alfaptr)malloc(sizeof(struct alfa)); node->x = x; + node->next = NULL;//added. + if (!front) + { front = node; - else { + rear = node;//added. + } + + else + { rear->next = node; rear = node; } @@ -27,7 +36,7 @@ void pop() { alfaptr node; if (!front) - printf("ERROR1"); + printf("ERROR1\n"); else { node = front->next; @@ -39,21 +48,30 @@ void search(int x) alfaptr node = front; int counter = 0; while (node) + { if (node->x == x) + { + counter++; printf("%d", counter); - else { - printf("ERROR2"); break; } + counter++; node = node->next; + } + if(counter == 0) + { + printf("ERROR@\n"); + } } + void rpop() {//pop last element alfaptr node = front; - while (node) + while (node->next->next) node = node->next; free(rear); rear = node; + rear->next->next =NULL; } void set() @@ -68,13 +86,16 @@ int size() alfaptr node = front; int count; while (node) - count++;node = node->next; + { + count++; + node = node->next;//added. + } return count; } void show() { - if (!front) { + if (front) {//removing !. for (int i = 0; i < MAX_SIZE; i++) printf("%d ", arr[i]); } @@ -97,7 +118,7 @@ int average() return sum / count; } -void main() +int main() { int cmd; long long int x; @@ -133,4 +154,4 @@ void main() exit(0); } } -} \ No newline at end of file +} diff --git a/4.cpp b/4.cpp index a9a32f2..879c04c 100644 --- a/4.cpp +++ b/4.cpp @@ -6,4 +6,5 @@ int main() float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); return 0; -} \ No newline at end of file + //the program prints value of arr[3]-arr[0].(=78.0) +} diff --git a/5.cpp b/5.cpp index 1be3d10..b2e7055 100644 --- a/5.cpp +++ b/5.cpp @@ -7,4 +7,5 @@ int main() printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); return 0; -} \ No newline at end of file + //the program prints value of arr[5]-arr[0](=50) and convert previous result to char. +} diff --git a/6.cpp b/6.cpp index f8b3141..8f734a8 100644 --- a/6.cpp +++ b/6.cpp @@ -7,5 +7,5 @@ int main() a = 512; x[0] = 1; printf("%d\n", a); - return 0; + return 0;//the program prints 513. } diff --git a/7.cpp b/7.cpp index 7b065a0..170cf16 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 + //the program prints 3. +} diff --git a/8.cpp b/8.cpp index ac3d613..56ce9c3 100644 --- a/8.cpp +++ b/8.cpp @@ -7,7 +7,7 @@ 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)); - + //the program prints 'Be' first and then prints 'WooW'. }