Tuesday, 18 March 2014

c program for implementing segmentation in memory using array

#include<stdio.h>
int main()
{
int a[10][10],b[100],i,j,n,x,base,size,seg,off;
printf("Enter the segments count\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the %d size \n",i+1);
scanf("%d",&size);
a[i][0]=size;
printf("Enter the base address\n");
scanf("%d",&base);
a[i][1]=base;

for(j=0;j<size;j++)
        {
        x=0;
        scanf("%d",&x);
//      b[base]=x;
        base++;
        b[base]=x;
        }
}
printf("Enter the segment number and offset value \n");
scanf("%d%d",&seg,&off);
if(off<a[seg][0])
{
int abs=a[seg][1]+off;
printf("the offset is less tha %d",a[seg][0]);
printf("\n %d + %d = %d\n",a[seg][1],off,abs);
printf("the element %d is at %d ",b[abs+1],abs);
}
else
{
printf("ERROr IN LOCATING");
}
}

5 comments:

  1. not appropriate for understanding please make it more clear
    thank you

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. mei kaise smjhu mujhe coding nhi aati mei BAO ka hun

    ReplyDelete
  4. input and output tho dena tha na!!!

    ReplyDelete