"banker's algorithm in C" Code Answer's

You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "banker's algorithm in C" answered properly. Developers are finding an appropriate answer about banker's algorithm in C related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like banker's algorithm in C. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on banker's algorithm in C. 

banker's algorithm in C

By Unsightly UnicornUnsightly Unicorn on May 29, 2021
#include <stdio.h>#include <stdbool.h> int main() {    int curr[5][5];    int max_claim[5][5];    int avl[5];    int alloc[5] = {0, 0, 0, 0, 0};    int max_res[5];    int running[5];     int i, j, exec, r, p;    int count = 0;    bool safe = false;     printf("\nEnter the number of resources: ");    scanf("%d", &r);     printf("\nEnter the number of processes: ");    scanf("%d", &p);    for (i = 0; i < p; i++) {        running[i] = 1;        count++;    }     printf("\nEnter Claim Vector: ");    for (i = 0; i < r; i++)        scanf("%d", &max_res[i]);     printf("\nEnter Allocated Resource Table: ");    for (i = 0; i < p; i++) {        for (j = 0; j < r; j++)            scanf("%d", &curr[i][j]);    }     printf("\nEnter Maximum Claim table: ");    for (i = 0; i < p; i++) {        for (j = 0; j < r; j++)            scanf("%d", &max_claim[i][j]);    }     printf("\nThe Claim Vector is: ");    for (i = 0; i < r; i++)        printf("%d ", max_res[i]);     printf("\nThe Allocated Resource Table:\n");    for (i = 0; i < p; i++) {        for (j = 0; j < r; j++)            printf("\t%d", curr[i][j]);        printf("\n");    }     printf("\nThe Maximum Claim Table:\n");    for (i = 0; i < p; i++) {        for (j = 0; j < r; j++)            printf("\t%d", max_claim[i][j]);        printf("\n");    }     for (i = 0; i < p; i++)        for (j = 0; j < r; j++)            alloc[j] += curr[i][j];     printf("\nAllocated resources: ");    for (i = 0; i < r; i++)        printf("%d ", alloc[i]);    for (i = 0; i < r; i++)        avl[i] = max_res[i] - alloc[i];     printf("\nAvailable resources: ");    for (i = 0; i < r; i++)        printf("%d ", avl[i]);    printf("\n");     while (count != 0) {        safe = false;        for (i = 0; i < p; i++) {            if (running[i]) {                exec = 1;                for (j = 0; j < r; j++) {                    if (max_claim[i][j] - curr[i][j] > avl[j]) {                        exec = 0;                        break;                    }                }                 if (exec) {                    printf("\nProcess%d is executing.\n", i + 1);                    running[i] = 0;                    count--;                    safe = true;                    for (j = 0; j < r; j++)                        avl[j] += curr[i][j];                    break;                }            }        }         if (!safe) {            printf("\nThe processes are in unsafe state.");            break;        }         if (safe)            printf("\nThe process is in safe state.");         printf("\nAvailable vector: ");        for (i = 0; i < r; i++)            printf("%d ", avl[i]);    }     return 0;}

Source: rosettacode.org

Add Comment

0

All those coders who are working on the Whatever based application and are stuck on banker's algorithm in C can get a collection of related answers to their query. Programmers need to enter their query on banker's algorithm in C related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about banker's algorithm in C for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of banker's algorithm in C while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "banker's algorithm in C". Visit this developer's friendly online web community, CodeProZone, and get your queries like banker's algorithm in C resolved professionally and stay updated to the latest Whatever updates. 

Whatever answers related to "banker's algorithm in C"

View All Whatever queries

Whatever queries related to "banker's algorithm in C"

Browse Other Code Languages

CodeProZone