From 6a26a8da908cf71d9e71eb0d62c398b5c5946c94 Mon Sep 17 00:00:00 2001 From: Tushar1sahyadri <102415361+Tushar1sahyadri@users.noreply.github.com> Date: Sat, 26 Mar 2022 17:36:57 +0530 Subject: [PATCH 1/5] Update fix_me.c --- fix_me.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fix_me.c b/fix_me.c index fa99550..f1ce0bb 100644 --- a/fix_me.c +++ b/fix_me.c @@ -9,7 +9,7 @@ int main() { scanf("%d %d", &number1, &number2); // calculating sum - sum = number1 - number2; + sum = number1 + number2; // Multiply number 1 and number 2 multi = number1 * number1 From 0f6bae8d02a1a774b1524bfe71083ecdff3a2e12 Mon Sep 17 00:00:00 2001 From: Tushar1sahyadri <102415361+Tushar1sahyadri@users.noreply.github.com> Date: Sat, 26 Mar 2022 17:47:05 +0530 Subject: [PATCH 2/5] Update fix_me.bhailang.txt --- fix_me.bhailang.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fix_me.bhailang.txt b/fix_me.bhailang.txt index e027aa7..365a49a 100644 --- a/fix_me.bhailang.txt +++ b/fix_me.bhailang.txt @@ -9,11 +9,11 @@ hi bhai agar bhai (b == 0) { bol bhai "b is equal to a"; - } nahi to bhai (b == a) { + } nahi to bhai (b =/= a) { bol bhai "b is equal to zero"; } - b += 1; + b += 0; } bye bhai From 0dd1e0cd17888ebf23e7f1bcc771281880f73f24 Mon Sep 17 00:00:00 2001 From: Tushar1sahyadri <102415361+Tushar1sahyadri@users.noreply.github.com> Date: Sat, 26 Mar 2022 17:49:35 +0530 Subject: [PATCH 3/5] Update fix_me.py --- fix_me.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fix_me.py b/fix_me.py index 1506169..534a523 100644 --- a/fix_me.py +++ b/fix_me.py @@ -4,10 +4,10 @@ a= int(input("Enter the first no: ")) b= int(input("Enter the second no: ")) # Divide two numbers -division= a-b +division= a/b # Square of first no. -a = a+a +a = a*a # Square of second no. b = b*b -print("Division",division) \ No newline at end of file +print("Division",division) From 1e5a5d2f947bbaca7e74c8b0ce67c808b8342445 Mon Sep 17 00:00:00 2001 From: Tushar1sahyadri <102415361+Tushar1sahyadri@users.noreply.github.com> Date: Sat, 26 Mar 2022 17:52:42 +0530 Subject: [PATCH 4/5] Update fix_me.cpp i had fixed with issues --- fix_me.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fix_me.cpp b/fix_me.cpp index 40b2599..6e29830 100644 --- a/fix_me.cpp +++ b/fix_me.cpp @@ -10,10 +10,10 @@ int main() { cin >> first_number >> second_number; // sum of two numbers in stored in variable sumOfTwoNumbers - product = first_number / second_number; + product = first_number * second_number; // prints sum cout << first_number << " + " << second_number << " = " << sum; return 0; -} \ No newline at end of file +} From fb697079edb6ee16ee05db2750202077114ed041 Mon Sep 17 00:00:00 2001 From: Tushar1sahyadri <102415361+Tushar1sahyadri@users.noreply.github.com> Date: Thu, 13 Jul 2023 06:35:57 +0000 Subject: [PATCH 5/5] commit --- DP.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 DP.c diff --git a/DP.c b/DP.c new file mode 100644 index 0000000..9ddeec8 --- /dev/null +++ b/DP.c @@ -0,0 +1,86 @@ +#include +#include +#include +#include +#define NUM_PHILOSOPHERS 5 +#define NUM_CHOPSTICKS 5 + +void dine(int n); +pthread_t philosopher[NUM_PHILOSOPHERS]; +pthread_mutex_t chopstick[NUM_CHOPSTICKS]; + +int main() +{ + // Define counter var i and status_message + int i, status_message; + void *msg; + + // Initialise the semaphore array + for (i = 1; i <= NUM_CHOPSTICKS; i++) + { + status_message = pthread_mutex_init(&chopstick[i], NULL); + // Check if the mutex is initialised successfully + if (status_message == -1) + { + printf("\n Mutex initialization failed"); + exit(1); + } + } + + // Run the philosopher Threads using *dine() function + for (i = 1; i <= NUM_PHILOSOPHERS; i++) + { + status_message = pthread_create(&philosopher[i], NULL, (void *)dine, (int *)i); + if (status_message != 0) + { + printf("\n Thread creation error \n"); + exit(1); + } + } + + // Wait for all philosophers threads to complete executing (finish dining) before closing the program + for (i = 1; i <= NUM_PHILOSOPHERS; i++) + { + status_message = pthread_join(philosopher[i], &msg); + if (status_message != 0) + { + printf("\n Thread join failed \n"); + exit(1); + } + } + + // Destroy the chopstick Mutex array + for (i = 1; i <= NUM_CHOPSTICKS; i++) + { + status_message = pthread_mutex_destroy(&chopstick[i]); + if (status_message != 0) + { + printf("\n Mutex Destroyed \n"); + exit(1); + } + } + return 0; +} +void dine(int n) +{ + printf("\nPhilosopher % d is thinking ", n); + + // Philosopher picks up the left chopstick (wait) + pthread_mutex_lock(&chopstick[n]); + + // Philosopher picks up the right chopstick (wait) + pthread_mutex_lock(&chopstick[(n + 1) % NUM_CHOPSTICKS]); + + // After picking up both the chopstick philosopher starts eating + printf("\nPhilosopher % d is eating ", n); + sleep(3); + + // Philosopher places down the left chopstick (signal) + pthread_mutex_unlock(&chopstick[n]); + + // Philosopher places down the right chopstick (signal) + pthread_mutex_unlock(&chopstick[(n + 1) % NUM_CHOPSTICKS]); + + // Philosopher finishes eating + printf("\nPhilosopher % d Finished eating ", n); +}