OneCompiler

OS14

105

#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, f = 0, p = 0, r, q = 0;
printf("Enter the number of memory frames: ");
scanf("%d", &n);
int frames[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) {
printf("Page %d -> Page Fault\n", r);
frames[f] = r;
f = (f + 1) % n;
p++;}
q++;}
printf("Total Page Faults: %d\n", p);
return 0;