Implement a program in C which a client is prompted to enter 2 arrays: the first
ID: 3889308 • Letter: I
Question
Implement a program in C which a client is prompted to enter 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 first fit, fitting as many requests as possible. After assignments are made, your program will report the first address assigned and the last address assigned inside each partition. For each partition, report internal fragmentation. Report all unassigned requests as “Not assigned
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.