#include<stdio.h>#include<stdlib.h>intmain(){intf[50],p,i,st,len,j,c,k,a,fn=0;for(i=0;i<50;i++)f[i]=0;x:fn=fn+1;printf("Enter index starting block and length: ");scanf("%d%d",&st,&len);k=len;if(f[st]==0){for(j=st;j<(st+k);j++){if(f[j]==0){f[j]=fn;printf("%d -------------->%d\n",j,f[j]);}else{printf("%d Block is already allocated \n",j);k++;}}}elseprintf("%d starting block is already allocated \n",st);printf("Do you want to enter more file(Yes - 1/No - 0)");scanf("%d",&c);if(c==1)gotox;elseexit(0);return0;}
#include<stdio.h>intmain(){intt[20],d[20],h,i,j,n,temp,k,atr[20],tot,p,sum=0;printf("enter the no of tracks to be traveresed");scanf("%d'",&n);printf("enter the position of head");scanf("%d",&h);t[0]=0;t[1]=h;printf("enter the tracks");for(i=2;i<n+2;i++)scanf("%d",&t[i]);for(i=0;i<n+2;i++){for(j=0;j<(n+2)-i-1;j++){if(t[j]>t[j+1]){temp=t[j];t[j]=t[j+1];t[j+1]=temp;}}}for(i=0;i<n+2;i++)if(t[i]==h){j=i;k=i;p=0;}while(t[j]!=0){atr[p]=t[j];j--;p++;}atr[p]=t[j];for(p=k+1;p<n+2;p++,k++)atr[p]=t[k+1];printf("seek sequence is:");for(j=0;j<n+1;j++){if(atr[j]>atr[j+1])d[j]=atr[j]-atr[j+1];elsed[j]=atr[j+1]-atr[j];sum+=d[j];printf("\n%d",atr[j]);}printf("\nTotal head movements:%d",sum);}
#include<stdio.h>voidmain(){inti,j,k,f,pf=0,count=0,rs[25],m[10],n;printf("\n Enter the length of reference string -- ");scanf("%d",&n);printf("\n Enter the reference string -- ");for(i=0;i<n;i++)scanf("%d",&rs[i]);printf("\n Enter no. of frames -- ");scanf("%d",&f);for(i=0;i<f;i++)m[i]=-1;printf("\n The Page Replacement Process is -- \n");for(i=0;i<n;i++){for(k=0;k<f;k++){if(m[k]==rs[i])break;}if(k==f){m[count++]=rs[i];pf++;}for(j=0;j<f;j++)printf("\t%d",m[j]);if(k==f)printf("\tPF No. %d",pf);printf("\n");if(count==f)count=0;}printf("\n The number of Page Faults using FIFO are %d",pf);}
#include<stdio.h>intmain(){inti,j,k,min,rs[25],m[10],count[10],flag[25],n,f,pf=0,next=1;printf("Enter the length of reference string -- ");scanf("%d",&n);printf("Enter the reference string -- ");for(i=0;i<n;i++){scanf("%d",&rs[i]);flag[i]=0;}printf("Enter the number of frames -- ");scanf("%d",&f);for(i=0;i<f;i++){count[i]=0;m[i]=-1;}printf("\nThe Page Replacement process is -- \n");for(i=0;i<n;i++){for(j=0;j<f;j++){if(m[j]==rs[i]){flag[i]=1;count[j]=next;next++;}}if(flag[i]==0){if(i<f){m[i]=rs[i];count[i]=next++;}else{min=0;for(j=1;j<f;j++)if(count[min]>count[j])min=j;m[min]=rs[i];count[min]=next;next++;}pf++;}for(j=0;j<f;j++)printf("%d\t",m[j]);if(flag[i]==0)printf("PF No. -- %d",pf);printf("\n");}printf("\nThe number of page faults using LRU are %d",pf);}
#include<stdio.h>#definemax25voidmain(){intfrag[max],b[max],f[max],i,j,nb,nf,temp,highest=0;staticintbf[max],ff[max];printf("\n\tMemory Management Scheme - Worst Fit");printf("\nEnter the number of blocks:");scanf("%d",&nb);printf("Enter the number of files:");scanf("%d",&nf);printf("\nEnter the size of the blocks:-\n");for(i=1;i<=nb;i++){printf("Block %d:",i);scanf("%d",&b[i]);}printf("Enter the size of the files :-\n");for(i=1;i<=nf;i++){printf("File %d:",i);scanf("%d",&f[i]);}for(i=1;i<=nf;i++){for(j=1;j<=nb;j++){if(bf[j]!=1)//ifbf[j]isnotallocated{temp=b[j]-f[i];if(temp>=0)if(highest<temp){ff[i]=j;highest=temp;}}}frag[i]=highest;bf[ff[i]]=1;highest=0;}printf("\nFile_no:\tFile_size :\tBlock_no:\tBlock_size:\tFragement");for(i=1;i<=nf;i++)printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);}
#include<stdio.h>#definemax25voidmain(){intfrag[max],b[max],f[max],i,j,nb,nf,temp,lowest=10000;staticintbf[max],ff[max];printf("\n\tMemory Management Scheme - Best Fit");printf("\nEnter the number of blocks:");scanf("%d",&nb);printf("Enter the number of files:");scanf("%d",&nf);printf("\nEnter the size of the blocks:-\n");for(i=1;i<=nb;i++){printf("Block %d:",i);scanf("%d",&b[i]);}printf("Enter the size of the files :-\n");for(i=1;i<=nf;i++){printf("File %d:",i);scanf("%d",&f[i]);}for(i=1;i<=nf;i++){for(j=1;j<=nb;j++){if(bf[j]!=1){temp=b[j]-f[i];if(temp>=0)if(lowest>temp){ff[i]=j;lowest=temp;}}}frag[i]=lowest;bf[ff[i]]=1;lowest=10000;}printf("\nFile No\tFile Size \tBlock No\tBlock Size\tFragment");for(i=1;i<=nf&&ff[i]!=0;i++)printf("\n%d\t\t%d\t\t%d\t\t%d\t\t%d",i,f[i],ff[i],b[ff[i]],frag[i]);//getch();}
Warning
LINK
You are about to visit a link which has been flagged with the above content warnings. Do you wish to continue?