Preview:
#include<stdio.h>

int size, base[100], limit[100], offset, flag, n;

int main() {
    printf("enter size of physical memory:");
    scanf("%d", &size);
    printf("enter no of segments:");
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        printf("enter limit of segment %d\n", i);
        scanf("%d", &limit[i]);
        if (limit[i] > size) {
            printf("\nlimit should not exceed physical memory\n");
            i--;
            continue;
        }
    }
    for (int i = 0; i < n; i++) {
        printf("enter base address of segment %d\n", i);
        scanf("%d", &base[i]);
        if (base[i] > size) {
            printf("\nbase address should not exceed physical memory\n");
            i--;
            continue;
        }
    }

    printf("segno\t\tbase\t\tlimit\n");
    for (int i = 0; i < n; i++) {
        printf("%d\t\t\t%d\t\t\t%d\n", i, base[i], limit[i]);
    }

    for (int i = 0; i < n; i++) {
        printf("seg %d occupied physical memory from %d to %d\n", i, base[i], base[i] + limit[i] - 1);
    }

    do {
        int j;
        printf("enter segment no");
        scanf("%d", &j);
        printf("enter offset");
        scanf("%d", &offset);
        printf("phy address %d\n", base[j] + offset);
        printf("to continue enter 1 else 0");
        scanf("%d", &flag);
    } while (flag != 0);

    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter