diff --git a/1.cpp b/1.cpp index fedde2c..4b4c4b1 100644 --- a/1.cpp +++ b/1.cpp @@ -4,7 +4,7 @@ using namespace std; -long long *b; +long long* 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]; - - for (int i = 10; i >= 0; i--) + long long* b; + long long* b = new long long[10]; + for (int i = 10-1; 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); } return b; } -void checkZeros(long long *a) +void checkZeros(long long int* a) { for (int i = 9; i >= 0; i--) { - if (a[i] = 0) + if (a[i] == 0) cout << "Zero Found" << endl; } } @@ -43,7 +43,7 @@ int main() } delete a; - cout<<"hello"; + cout<<"hello"<x = x; if (!front) + { front = node; + front->next=NULL; + rear = node; + } else { rear->next = node; rear = node; @@ -27,33 +31,39 @@ void pop() { alfaptr node; if (!front) - printf("ERROR1"); + printf("ERROR1!\n"); else { node = front->next; front = node; } } -void search(int x) +void search(long long int x) { alfaptr node = front; int counter = 0; - while (node) + int flag = 0; + while (node!=NULL) + { if (node->x == x) + { printf("%d", counter); - else { - printf("ERROR2"); + flag = 1; break; } node = node->next; + } + if (flag == 0) + printf("ERROR2\n"); } void rpop() {//pop last element alfaptr node = front; - while (node) + while (node->next->next!=NULL) node = node->next; - free(rear); - rear = node; + alfaptr temp = node->next; + node->next = NULL; + free(temp); } void set() @@ -66,9 +76,12 @@ void set() int size() { alfaptr node = front; - int count; + int count = 0; while (node) - count++;node = node->next; + { + count++; + node = node->next; + } return count; } @@ -80,24 +93,23 @@ void show() } else { - printf("ERROR3"); + printf("ERROR3\n"); } } -int average() +float average() { - alfaptr node = front; - int sum = 0, count; + int sum = 0, count = 0; while (node) { sum += node->x; count++; node = node->next; } - return sum / count; + return (float)sum / count; } -void main() +int main() { int cmd; long long int x; diff --git a/4.cpp b/4.cpp index a9a32f2..5ad825b 100644 --- a/4.cpp +++ b/4.cpp @@ -5,5 +5,6 @@ int main() float *ptr1 = &arr[0]; float *ptr2 = ptr1 + 3; printf("%f", *ptr2 - *ptr1); + //Output is 78.0000 return 0; } \ No newline at end of file diff --git a/5.cpp b/5.cpp index 1be3d10..bb6332c 100644 --- a/5.cpp +++ b/5.cpp @@ -6,5 +6,6 @@ int main() int *ptr2 = arr + 5; printf("%d\n", (*ptr2 - *ptr1)); printf("%c", (char)(*ptr2 - *ptr1)); + //Out put is 20 \n 5 return 0; } \ No newline at end of file diff --git a/6.cpp b/6.cpp index f8b3141..d8f21a0 100644 --- a/6.cpp +++ b/6.cpp @@ -7,5 +7,6 @@ int main() a = 512; x[0] = 1; printf("%d\n", a); + //Output is 513 return 0; } diff --git a/7.cpp b/7.cpp index 7b065a0..5f5fe9b 100644 --- a/7.cpp +++ b/7.cpp @@ -6,5 +6,6 @@ int main() ++*p; p += 2; printf("%d", *p); + //Output is a number it is 3 return 0; } \ No newline at end of file diff --git a/7.exe b/7.exe new file mode 100644 index 0000000..072f561 Binary files /dev/null and b/7.exe differ diff --git a/8.cpp b/8.cpp index ac3d613..8b6af64 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)); - - - + //this code is OK.Output is Be WooW + return 0; }