Thursday, August 27, 2009

Multiple Instance


#include<stdio.h>



#include<conio.h>




void

main()



{



int ra[10],rb[10],rc[10],aa[10],ab[10],ac[10],na[10],nb[10],nc[10];



int n,i,a,b,c,t=0,x,y,z,f[10]={0};



char ch;



clrscr();



printf("\n\n\t\tMULTIPLE
INSTANCE"
);



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



printf("\nEnter
the No. of Process:"
);



scanf("%d",&n);



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



{



printf("\n\tProcess
P%d:"
,i);



printf("\nEnter
the No. of Maximum Resources in type A:"
);



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



printf("\nEnter
the No. of Maximum Resources in type B:"
);



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



printf("\nEnter
the No. of Maximum Resources in type C:"
);



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



do



{



printf("\nEnter
the No. of Allocation Type A:(<=%d):"
,ra[i]);



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



}while(aa[i]>ra[i]);



do



{



printf("\nEnter
the No. of Allocation Type B:(<=%d):"
,rb[i]);



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



}while(ab[i]>rb[i]);



do



{



printf("\nEnter
the No. of Allocation Type C:(<=%d):"
,rc[i]);



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



}while(ac[i]>rc[i]);



}



printf("\n\nEnter
the number of Resources Available in A:"
);



scanf("%d",&a);



printf("\n\nEnter
the number of Resources Available in B:"
);



scanf("%d",&b);



printf("\n\nEnter
the number of Resources Available in C:"
);



scanf("%d",&c);



do



{



printf("\n\nProcess\t Request\tallocation\tResource Need\tavilable");



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



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



{



na[i]=ra[i]-aa[i];



nb[i]=rb[i]-ab[i];



nc[i]=rc[i]-ac[i];



printf("\nP%d\t %d
%d %d\t%d
%d %d\t\t%d
%d %d"
,



i,ra[i],rb[i],rc[i],aa[i],ab[i],ac[i],na[i],nb[i],nc[i]);



if(i==1)



printf("\t\t%d %d
%d"
,a,b,c);



}



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



f[i]=0;



i=1;x=a;y=b;z=c;t=0;



while(i<=n)



{




if
((f[i]==0)&&(na[i]<=x)&&(nb[i]<=y)&&(nc[i]<=z))



{




x=x+aa[i];




y=y+ab[i];




z=z+ac[i];




f[i]=1;




t++;




i=1;



}



else



i++;



}



if(t==n)



printf("\n\n\t\tThe
System is in safe state"
);



else



{



printf("\n\n\t\t
The System is in Unsafe state"
);



exit();



}



printf("\n\n\tAdditional
Resources Allocation"
);



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



printf("\nEnter
the Process No.:"
);



scanf("%d",&t);



printf("\n\tIn
Process P%d:"
,t);



printf("\nEnter
the No. of Additional Resources in type A:"
);



scanf("%d",&x);



printf("\nEnter
the No. of Additional Resources in type B:"
);



scanf("%d",&y);



printf("\nEnter
the No. of Additional Resources in type C:"
);



scanf("%d",&z);



if((x<=a)&&(y<=b)&&(z<=c))



printf("\n\n\tThe
Request accepted\n\tThe resourcess are granted immediatley"
);



else



printf("\n\n\tThe
Request is NOT accepted"
);



fflush(stdin);



printf("\n\n\t\tDo
you continue(Y/N):"
);



scanf("%c",&ch);



}while((ch=='y')(ch=='Y'));



}


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