diff --git a/1.cpp b/1.cpp index fedde2c..dff9501 100644 --- a/1.cpp +++ b/1.cpp @@ -13,11 +13,12 @@ long long int factorial(int n) long long int *producingTheFactorialFractions() { - long long b[10]; - - for (int i = 10; i >= 0; i--) + //delet long long b[10]; + b = new long long [10]; //assign memory + // i = 9 + 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);// long long int } return b; } @@ -26,7 +27,8 @@ void checkZeros(long long *a) { for (int i = 9; i >= 0; i--) { - if (a[i] = 0) + // we need == not = + if (a[i] == 0) cout << "Zero Found" << endl; } } @@ -34,7 +36,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,7 +45,8 @@ int main() } delete a; - cout<<"hello"; + //add endl + cout<<"hello"<x = x; + node->next = NULL;// if (!front) - front = node; + + front = rear =node ;//added rear else { rear->next = node; rear = node; @@ -27,7 +29,7 @@ void pop() { alfaptr node; if (!front) - printf("ERROR1"); + printf("ERROR1\n");// added "\n" else { node = front->next; @@ -39,21 +41,29 @@ void search(int x) alfaptr node = front; int counter = 0; while (node) + { if (node->x == x) - printf("%d", counter); - else { - printf("ERROR2"); - break; + { + counter++; } node = node->next; + } + if (counter == 0) { + printf("ERROR2\n");// added "\n" + } + else + { + printf("%d\n", counter); + } } 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,19 +78,23 @@ int size() alfaptr node = front; int count; while (node) - count++;node = node->next; + { + count++; + node = node->next;// put commands in parentheses + } + return count; } void show() { - if (!front) { + if (front) {//deleted ! for (int i = 0; i < MAX_SIZE; i++) printf("%d ", arr[i]); } else { - printf("ERROR3"); + printf("ERROR3\n");// added "\n" } } @@ -97,7 +111,7 @@ int average() return sum / count; } -void main() +int main() { int cmd; long long int x; @@ -127,10 +141,10 @@ void main() show(); break; case 7://size - printf("%d", size()); + printf("%d\n", size());//added "\n" break; case 10: exit(0); } } -} \ No newline at end of file +} diff --git a/4.cpp b/4.cpp index a9a32f2..4373338 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 +} +// This program prints vlue of arr[3]-arr[0] -> 90.5-12.5 = 78 \ No newline at end of file diff --git a/5.cpp b/5.cpp index 1be3d10..2f24066 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 +} +// This program prints vlue of arr[5] - arr[0] (60 - 10 = 50) and symbol of 2 in ascii code. \ No newline at end of file diff --git a/6.cpp b/6.cpp index f8b3141..9fcc031 100644 --- a/6.cpp +++ b/6.cpp @@ -9,3 +9,7 @@ int main() printf("%d\n", a); return 0; } +/* +In first, x[0] = 0 0 0 0 0 0 0 0 = 0 and x[1] = 0 0 0 0 0 0 1 0 = 512 and a = 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0. +When we assgin 1 to x[0] becomes 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 that is equal to 513. +*/ diff --git a/7.cpp b/7.cpp index 7b065a0..2bb10e9 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 +} +// This program adds 1 unit to arr[0] but prints arr[2]. \ No newline at end of file diff --git a/8.cpp b/8.cpp index ac3d613..d97cf38 100644 --- a/8.cpp +++ b/8.cpp @@ -7,7 +7,6 @@ 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" in first printf +//"WooW" in second printf \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 83cba6d..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# ApLabGitPractice -A Repo for My Students in Advanced Programming Workshop to practice what they have learn about Git & GitHub