OS16
#include <stdio.h>
#include <time.h>
int main() {
clock_t start_time, end_time;
double execution_time;
start_time = clock();
for (int i = 0; i < 1000000; i++) {
int result = i * i;}
end_time = clock();
execution_time = (double)(end_time - start_time) / CLOCKS_PER_SEC;
printf("Execution time: %f seconds\n", execution_time);
return 0;
#2
#include <stdio.h>
#include <stdlib.h>
int main() {
int n, p = 0, r, q = 0;
printf("Enter the number of memory frames: ");
scanf("%d", &n);
int frames[n];
int nextUse[n];
printf("Reference String: ");
while (scanf("%d", &r) != EOF) {
int found = 0;
for (int i = 0; i < n; i++) {
if (frames[i] == r) {
found = 1;
break;}}
if (!found) {
int toReplace = -1;
for (int i = 0; i < n; i++) {
nextUse[i] = q + 1;
for (int j = q + 1; j < q + 1; j++) {
if (r == frames[i]) {
nextUse[i] = j;
break;}}}
for (int i = 0; i < n; i++) {
if (nextUse[i] == q + 1) {
toReplace = i;
break;}}
if (toReplace == -1) {
toReplace = 0;
for (int i = 1; i < n; i++) {
if (nextUse[i] > nextUse[toReplace]) {
toReplace = i;}}}
frames[toReplace] = r;
p++;
printf("Page %d -> Page Fault\n", r);}
q++;}
printf("Total Page Faults: %d\n", p);
return 0;