Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- void main()
- {
- int mem, blk, pr, info[100], blkn=0, i, n, ifrag=0, efrag;
- printf(" Enter Memory Size: ");
- scanf("%d", &mem);
- printf(" Enter Block Size: ");
- scanf("%d", &blk);
- blkn=mem/blk;
- efrag=mem-blkn*blk;
- printf("\n Available Block Number: %d \n", blkn);
- printf(" Enter The Number of Process: ");
- scanf("%d", &n);
- for (i=1; i<=n; i++)
- {
- printf(" Enter the information of P%d: ", i);
- scanf("%d", &info[i]);
- }
- printf("\nProcess \t Mem Req \t Allowed \t Int. Frag\n");
- pr=0;
- if(blkn!=0)
- {
- for(i=1; i<=n && pr<=blkn; i++)
- {
- printf("\n %d\t\t%d", i+1, info[i]);
- if(info[i]>blk)
- {
- printf("\t\tNo\t\t---");
- }
- else
- {
- int temp=blk-info[i];
- printf("\t\tYes\t%d", temp);
- ifrag=ifrag+temp;
- pr++;
- }
- }
- if(i<n)
- {
- printf("Memory is full");
- }
- printf("\nTotal Internal Fragmentation: %d", ifrag);
- printf("\nTotal External Fragmentation: %d", efrag);
- }
- else printf("There is not available any block");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement