From 84a8e26f988ffc60db807adfd69fcacf93426143 Mon Sep 17 00:00:00 2001 From: GAURAV PATIL <67456816+GauravPatil8778@users.noreply.github.com> Date: Thu, 1 Oct 2020 11:54:48 +0530 Subject: [PATCH 1/7] Create recursion.c --- mathematical/recursion.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 mathematical/recursion.c diff --git a/mathematical/recursion.c b/mathematical/recursion.c new file mode 100644 index 0000000..3f5bc74 --- /dev/null +++ b/mathematical/recursion.c @@ -0,0 +1,16 @@ +#include +long int multiplyNumbers(int n); +int main() { + int n; + printf("Enter a positive integer: "); + scanf("%d",&n); + printf("Factorial of %d = %ld", n, multiplyNumbers(n)); + return 0; +} + +long int multiplyNumbers(int n) { + if (n>=1) + return n*multiplyNumbers(n-1); + else + return 1; +} From ce1d79be955d93d6062413485100767f30903955 Mon Sep 17 00:00:00 2001 From: GAURAV PATIL <67456816+GauravPatil8778@users.noreply.github.com> Date: Thu, 1 Oct 2020 11:56:17 +0530 Subject: [PATCH 2/7] Create recursion.c --- CODE in C/mathematical/recursion.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CODE in C/mathematical/recursion.c diff --git a/CODE in C/mathematical/recursion.c b/CODE in C/mathematical/recursion.c new file mode 100644 index 0000000..3f5bc74 --- /dev/null +++ b/CODE in C/mathematical/recursion.c @@ -0,0 +1,16 @@ +#include +long int multiplyNumbers(int n); +int main() { + int n; + printf("Enter a positive integer: "); + scanf("%d",&n); + printf("Factorial of %d = %ld", n, multiplyNumbers(n)); + return 0; +} + +long int multiplyNumbers(int n) { + if (n>=1) + return n*multiplyNumbers(n-1); + else + return 1; +} From 28c02cdccf8465efcef39bc76e9f9e1a9263c3ae Mon Sep 17 00:00:00 2001 From: GAURAV PATIL <67456816+GauravPatil8778@users.noreply.github.com> Date: Thu, 1 Oct 2020 11:56:52 +0530 Subject: [PATCH 3/7] Delete recursion.c --- mathematical/recursion.c | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 mathematical/recursion.c diff --git a/mathematical/recursion.c b/mathematical/recursion.c deleted file mode 100644 index 3f5bc74..0000000 --- a/mathematical/recursion.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -long int multiplyNumbers(int n); -int main() { - int n; - printf("Enter a positive integer: "); - scanf("%d",&n); - printf("Factorial of %d = %ld", n, multiplyNumbers(n)); - return 0; -} - -long int multiplyNumbers(int n) { - if (n>=1) - return n*multiplyNumbers(n-1); - else - return 1; -} From f29efac293f65adba08a3ca225b3418c1b003e63 Mon Sep 17 00:00:00 2001 From: GAURAV PATIL <67456816+GauravPatil8778@users.noreply.github.com> Date: Thu, 1 Oct 2020 11:57:17 +0530 Subject: [PATCH 4/7] Delete recursion.c --- CODE in C/mathematical/recursion.c | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 CODE in C/mathematical/recursion.c diff --git a/CODE in C/mathematical/recursion.c b/CODE in C/mathematical/recursion.c deleted file mode 100644 index 3f5bc74..0000000 --- a/CODE in C/mathematical/recursion.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -long int multiplyNumbers(int n); -int main() { - int n; - printf("Enter a positive integer: "); - scanf("%d",&n); - printf("Factorial of %d = %ld", n, multiplyNumbers(n)); - return 0; -} - -long int multiplyNumbers(int n) { - if (n>=1) - return n*multiplyNumbers(n-1); - else - return 1; -} From d396553172a33560d67cc92398b7b8631ed9f3a3 Mon Sep 17 00:00:00 2001 From: GAURAV PATIL <67456816+GauravPatil8778@users.noreply.github.com> Date: Thu, 1 Oct 2020 11:58:29 +0530 Subject: [PATCH 5/7] Create Factorial.c --- CODE in C/Mathematical/Factorial.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 CODE in C/Mathematical/Factorial.c diff --git a/CODE in C/Mathematical/Factorial.c b/CODE in C/Mathematical/Factorial.c new file mode 100644 index 0000000..3f5bc74 --- /dev/null +++ b/CODE in C/Mathematical/Factorial.c @@ -0,0 +1,16 @@ +#include +long int multiplyNumbers(int n); +int main() { + int n; + printf("Enter a positive integer: "); + scanf("%d",&n); + printf("Factorial of %d = %ld", n, multiplyNumbers(n)); + return 0; +} + +long int multiplyNumbers(int n) { + if (n>=1) + return n*multiplyNumbers(n-1); + else + return 1; +} From 5bdebb6db79dfbb139e4cde7e4cbbd88bbf19ba0 Mon Sep 17 00:00:00 2001 From: GAURAV PATIL <67456816+GauravPatil8778@users.noreply.github.com> Date: Thu, 1 Oct 2020 12:03:54 +0530 Subject: [PATCH 6/7] Create factorial_in_c++.cpp --- CODE in C/Mathematical/factorial_in_c++.cpp | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 CODE in C/Mathematical/factorial_in_c++.cpp diff --git a/CODE in C/Mathematical/factorial_in_c++.cpp b/CODE in C/Mathematical/factorial_in_c++.cpp new file mode 100644 index 0000000..81fbce5 --- /dev/null +++ b/CODE in C/Mathematical/factorial_in_c++.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; + +int factorial(int n); + +int main() +{ + int n; + + cout << "Enter a positive integer: "; + cin >> n; + + cout << "Factorial of " << n << " = " << factorial(n); + + return 0; +} + +int factorial(int n) +{ + if(n > 1) + return n * factorial(n - 1); + else + return 1; + } From 663fd6875f3b6116deffd2abcbd7d1b7b48675bd Mon Sep 17 00:00:00 2001 From: GAURAV PATIL <67456816+GauravPatil8778@users.noreply.github.com> Date: Thu, 1 Oct 2020 12:37:36 +0530 Subject: [PATCH 7/7] Create node_delete.cpp --- CODE in C/Data Structures/node_delete.cpp | 89 +++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 CODE in C/Data Structures/node_delete.cpp diff --git a/CODE in C/Data Structures/node_delete.cpp b/CODE in C/Data Structures/node_delete.cpp new file mode 100644 index 0000000..31e1505 --- /dev/null +++ b/CODE in C/Data Structures/node_delete.cpp @@ -0,0 +1,89 @@ + +#include +using namespace std; + +/* Link list node */ +struct Node { + int data; + struct Node* next; +}; + +// Fucntion to delete the node without head +void deleteNodeWithoutHead(struct Node* pos) +{ + if (pos == NULL) // If linked list is empty + return; + else { + + if (pos->next == NULL) { + printf("This is last node, require head, can't be freed\n"); + return; + } + + struct Node* temp = pos->next; + + // Copy data of the next node to current node + pos->data = pos->next->data; + + // Perform conventional deletion + pos->next = pos->next->next; + + free(temp); + } +} + +// Function to print the linked list +void print(Node* head) +{ + Node* temp = head; + while (temp) { + cout << temp->data << " -> "; + temp = temp->next; + } + + cout << "NULL"; +} + +void push(struct Node** head_ref, int new_data) +{ + /* allocate node */ + struct Node* new_node = new Node(); + + /* put in the data */ + new_node->data = new_data; + + /* link the old list off the new node */ + new_node->next = (*head_ref); + + /* move the head to point to the new node */ + (*head_ref) = new_node; +} + +// Driver Code +int main() +{ + /* Start with the empty list */ + struct Node* head = NULL; + + // create linked 35->15->4->20 + push(&head, 20); + push(&head, 4); + push(&head, 15); + push(&head, 35); + cout << "Initial Linked List: \n"; + print(head); + cout << endl + << endl; + + // Delete 15 without sending head + Node* del = head->next; + deleteNodeWithoutHead(del); + + // Print the final linked list + cout << "Final Linked List after deletion of 15:\n"; + print(head); + + return 0; + + // This code has been contributed by Striver +}