zzz

 #include <stdio.h>

#include <math.h>


int main() {

    char studentID[20], studentName[50];

    int logicalAddressSpace, numPages, totalMemorySpace, numFrames;

    int pageSizeBytes;

    int bitsForPage, bitsForFrame, bitsForOffset;

    int logicalAddressSize, physicalAddressSize;


    // Taking inputs

    printf("Enter Your Student ID: ");

    scanf("%s", studentID);

    getchar();  // Clear newline character from buffer


    printf("Enter Your Student Name: ");

    fgets(studentName, sizeof(studentName), stdin);


    printf("Enter Logical Address Space Information (in KB): ");

    scanf("%d", &logicalAddressSpace);


    printf("Enter number of pages: ");

    scanf("%d", &numPages);


    printf("Enter total memory (in KB): ");

    scanf("%d", &totalMemorySpace);


    printf("Enter number of frames: ");

    scanf("%d", &numFrames);


    // Calculations

    pageSizeBytes = (logicalAddressSpace * 1024) / numPages;

    bitsForPage = (int) ceil(log2(numPages));

    bitsForFrame = (int) ceil(log2(numFrames));

    bitsForOffset = (int) ceil(log2(pageSizeBytes));


    logicalAddressSize = bitsForPage + bitsForOffset;

    physicalAddressSize = bitsForFrame + bitsForOffset;


    // Output

    printf("\nCalculated Output:\n");

    printf("No. of bits needed for p (page number): %d\n", bitsForPage);

    printf("No. of bits needed for f (frame number): %d\n", bitsForFrame);

    printf("No. of bits needed for d (offset): %d\n", bitsForOffset);

    printf("Logical address size: %d bits\n", logicalAddressSize);

    printf("Physical address size: %d bits\n", physicalAddressSize);


    return 0;

Post a Comment

0 Comments