Untitled
unknown
plain_text
a year ago
4.6 kB
14
Indexable
7 //FIFO #include<stdio.h> void main() { int i, 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); } //LRU #include<stdio.h> int main() { int i, 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; 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); } 8 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_FILES 10 #define MAX_FILENAME_LENGTH 10 char directoryName[MAX_FILENAME_LENGTH]; char filenames[MAX_FILES][MAX_FILENAME_LENGTH]; int fileCount = 0; void createFile() { if (fileCount < MAX_FILES) { char filename[MAX_FILENAME_LENGTH]; printf("Enter the name of the file: "); scanf("%s", filename); strcpy(filenames[fileCount], filename); fileCount++; printf("File %s created.\n", filename); } else { printf("Directory is full, cannot create more files.\n"); } } void deleteFile() { if (fileCount == 0) { printf("Directory is empty, nothing to delete.\n"); return; } char filename[MAX_FILENAME_LENGTH]; printf("Enter the name of the file to delete: "); scanf("%s", filename); int found = 0; for (int i = 0; i < fileCount; i++) { if (strcmp(filename, filenames[i]) == 0) { found = 1; printf("File %s is deleted.\n", filename); strcpy(filenames[i], filenames[fileCount - 1]); fileCount--; break; } } if (!found) { printf("File %s not found.\n", filename); } } void displayFiles() { if (fileCount == 0) { printf("Directory is empty.\n"); } else { printf("Files in the directory %s:\n", directoryName); for (int i = 0; i < fileCount; i++) { printf("\t%s\n", filenames[i]); } } } int main() { printf("Enter the name of the directory: "); scanf("%s", directoryName); while (1) { printf("\n1. Create File\t2. Delete File\t3. Search File\n4. Display Files\t5. Exit\nEnter your choice:"); int choice; scanf("%d", &choice); switch (choice) { case 1: createFile(); break; case 2: deleteFile(); break; case 3: printf("Enter the name of the file: "); char searchFilename[MAX_FILENAME_LENGTH]; scanf("%s", searchFilename); int found = 0; for (int i = 0; i < fileCount; i++) { if (strcmp(searchFilename, filenames[i]) == 0) { found = 1; printf("File %s is found.\n", searchFilename); break; } } if (!found) { printf("File %s not found.\n", searchFilename); } break; case 4: displayFiles(); break; case 5: exit(0); default: printf("Invalid choice, please try again.\n"); } } return 0; } 9 #include <stdio.h> #include <stdlib.h> int main(){ int f[50], p, i, st, len, j, c, k, a, fn=0; for (i = 0; i < 50; i++) f[i] = 0; /* printf("Enter how many blocks already allocated: "); scanf("%d", &p); printf("Enter blocks already allocated: "); for (i = 0; i < p; i++) { scanf("%d", &a); f[a] = 1; }*/ 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++; } } } else printf("%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) goto x; else exit(0); return 0; }
Editor is loading...
Leave a Comment