Write a C program in which a client is prompted to enter an 2 arrays: the first
ID: 3746179 • Letter: W
Question
Write a C program in which a client is prompted to enter an 2 arrays: the first will designate the sizes of a number of fixed –size memory partitions, the second will designate a sequence of memory requests as though coming from several users. Your program will assign the memory requests to the partitions in order using BEST FIT, fitting as many requests as possible.As partitions are filled, you will need to mark them busy. Report the first address assigned, the last address assigned and the internal fragmentation for each partition.Report unassigned partittions adn the begining address of each
Print an error message for the following: input values of zero and negatve, requests that are larger than the largest partition, and legitimate requests that do not have an available partition to be place in
Expected Output:
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
int main(){
int n;
int *data;
int seq[10];
char ord[6];
int i = 0;
int j;
printf("Enter of number of fixed size memory partitons(20 bytes) :");
scanf("%d",&n);
data = (int *)malloc(sizeof(int) * n);
for (i = 0; i<n; i++){
data[i] = 0;
}
printf("Enter 6 entries as sequence of requests :");
for(i=0; i<6; i++){
scanf("%d", &seq[i]);
}
for(i=0; i<6; i++){
ord[i] = 'N';
}
for (i = 0; i<6; i++){
for (j=0; j<n; j++){
if (seq[i] <= (20 - data[j])){
ord[i] = 'A';
data[j] = data[j] + seq[i];
break;
}
}
}
for (i = 0; i<6; i++){
printf("Request no %d Requested size: %d ", i, seq[i]);
if (ord[i] == 'A')
printf(" %s ", "Assigned");
else
printf(" %s ", " Not Assigned");
}
printf ("Internal Fragementation : ");
for (i = 0; i<n; i++){
if (data[i] != 0 && data[i] != 20)
printf("Partition no %d fragmentation: %d ", i, 20 -data[i]);
else
printf("Partition no %d fragmentation: None ",i);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.