Thursday, August 27, 2009

Memory Allocation



#include<stdio.h>



#include<conio.h>




void

main()



{



int i,j,s[10],s1[10],m,n,t,a[10],ch;



clrscr();



printf("\n\n\t\tMEMORY
ALLOCATION"
);



printf("\n\t\t~~~~~~~~~~~~~~~~~~");



printf("\n\nEnter
the no of slots:"
);



scanf("%d",&n);



for(i=1;i<=n;i++)



{



printf("Enter
the slot %d size:"
,i);



scanf("%d",&s[i]);



a[i]=i;



s1[i]=s[i];



}



printf("\nEnter
the Memory size:"
);



scanf("%d",&m);



for(i=1;i<=n;i++)



for(j=1;j<=n;j++)



if(s[i]<s[j])



{



t=s[i];



s[i]=s[j];



s[j]=t;



t=a[i];



a[i]=a[j];



a[j]=t;



}



do



{



printf("\n\nSelect
the choice:"
);



printf("\n\t1.
First Bit.\n\t2. Best Bit.\n\t3. Worst Bit.\n\t4. Exit"
);



printf("\nEnter
the choice:"
);



scanf("%d",&ch);



switch(ch)



{



case
1:




printf("\n\tFIRST BIT ALLOCATION");




printf("\n\t~~~~~~~~~~~~~~~~~~~~");




for(i=1;i<=n;i++)




if(m<=s1[i])




{




printf("\nThe first bit memory
allocation in slot => %d"
,i);




break;




}




break;



case
2:




printf("\n\tBEST BIT ALLOCATION");




printf("\n\t~~~~~~~~~~~~~~~~~~");




for(i=1;i<=n;i++)




if(m<=s[i])




{




printf("\nThe best bit memory
allocation in slot => %d"
,a[i]);




break;




}




break;



case
3:




printf("\n\tWORST BIT ALLOCATION");




printf("\n\t~~~~~~~~~~~~~~~~~~~~");




for(i=n;i>=1;i--)




if(m<s[i])




{




printf("\nThe Worst bit memory
allocation in slot => %d"
,a[i]);




break;




}




break;



}



}while(ch<=3);



}

Click to Download Source Code
or
Copy and past in browser address bar

http://sites.google.com/site/senthilmcan/software-programs


No comments:

Post a Comment