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

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


Smokers Algorithem



#include<stdio.h>



#include<conio.h>



main()



{



static
char item[3][9]={"PAPER","TOBACCO","MATCHBOX"};



char ch;



int a,b,i;



clrscr();



printf("\n\n\t\tSMOKERS
ALGORITHM"
);



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



do



{



AB:



printf("\nSelect
the Two Item:"
);



printf("\n\t\tItemNo\tItem");



printf("\n\t\t 1\tPaper\n\t\t
2\tTobacco\n\t\t 3\tMatchbox"
);



printf("\n\tEnter
Two Itemno Supplied By Agent : "
);



scanf("%d%d",&a,&b);



a=a-1;



b=b-1;



if((a>2)(a<0)(b>2)(b<0)(a==b))



{



printf("\n\t\tInvalid
Input,Try Again.."
);



getch();



goto
AB;



}



printf("\n\tItems
Supplied By Agent : %s & %s"
,item[a],item[b]);



for(i=0;i<=2;i++)



{



if((i!=a)&&(i!=b))



printf("\n\tSmoker
Already Have Item : %s"
,item[i]);



}



printf("\n\n\t\tDo
You Want To Continue (Y/y) : "
);



fflush(stdin);



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


Average Turn around Time Calculation



#include<stdio.h>



#include<conio.h>




void

main()



{



int ch,i,j,n,pd[10],pd1[10];



float aw,at,t,k;



clrscr();



printf("\n\n\t\tAverage
Turn Around Time Calculation"
);



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



do



{



printf("\n
Enter the number of Process(n>2):"
);



scanf("%d",&n);



}while(n<2);



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



{



printf("\nEnter
the CPU Burst Time of process %d:"
,i);



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



}



do



{



printf("\n\nSelect
the Scheduling Choice:"
);



printf("\n\t1.First
Come First Service(FCFS)"
);



printf("\n\t2.Shortest
Job First(SJF)"
);



printf("\n\t3.Exit\n\tEnter
Your Choice:"
);



scanf("%d",&ch);



switch(ch)



{



case
1:



printf("\n\n\t\tFirst
Come First Service(FCFS)"
);



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



t=aw=at=k=0;



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



{




k=k+t;




t=t+pd[i];




}



aw=k/n;



at=t/n;



printf("\n\n\tAverage
waiting time => %4.2f"
,aw);



printf("\n\n\tAverage
process time => %4.2f"
,at);



printf("\n\n\tAverage
Turn Around time => %4.2f"
,aw+at);



break;



case
2:



printf("\n\n\t\tShortest
Job First(SJF)"
);



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



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




pd1[i] = pd[i];



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




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




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




{




t = pd1[i]; pd1[i] = pd1[j]; pd1[j] = t;




}




t=k=0;



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



{




k=k+t;




t=t+pd1[i];



}



aw=k/n;



at=t/n;



printf("\n\n\tAverage
waiting time => %4.2f"
,aw);



printf("\n\n\tAverage
process time => %4.2f"
,at);



printf("\n\n\tAverage
turn Around time =>%4.2f"
,aw+at);



break;



}



}while(ch<=2);



}

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

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


Deadlock Handling



#include<stdio.h>



#include<conio.h>




void

main()



{



int r[10]={0},al[10]={0},ar,t=0,nr[10],n,i,p[10],a[10];



char ch;



clrscr();



printf("\n\n\t\tDeadlock
Handling"
);



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



do



{



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:"
);



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



do



{



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



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



}while(al[i]>r[i]);



}



printf("\n\nEnter
the number of Resource Available:"
);



scanf("%d",&ar);



printf("\n\tProcess\t\tMax\tAllocation\t\tAvailable");



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



{



printf("\n\tP%d\t\t",i);



printf("%d\t%d",r[i],al[i]);



if(i==1)



printf("\t\t\t%d
"
,ar);



}



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



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



printf("\n\n\tProcess\t\tNo.
of Resource Need"
);



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



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



{



nr[i]=r[i]-al[i];



printf("\n\tP%d\t\t%d",i,nr[i]);



}



t=0;



printf("\n\nProcess
Execution Order is =>\n\t<"
);



i=1;



while(i<=n)



{



if((nr[i]<=ar)&&(nr[i]!=1000))



{



printf(" P%d",i);



nr[i]=1000;



ar=ar+al[i];



t++;



i=1;



}



else
if(nr[i]==0)



{



printf(" P%d",i);



nr[i]=1000;



ar=ar+al[i];



t++;



i=1;



}



else



i++;



}



printf("
>"
);



if(t<n)



printf("\n\n\t\tDeadlock
is Occured"
);



fflush(stdin);



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



scanf("%c",&ch);



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



getch();



}

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

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


Job scheduling



#include<stdio.h>



#include<conio.h>




int

pd[10],pd1[10],pd2[10];




void

main()



{



int c=50,ch,i,j,k,l,m=0,max=0,n,p[10],pp[10],pr,t,tq,ti;



int pt[10],pri[10];



int a[10];



void line(int);



void space(int);



clrscr();



printf("\n\n\t\tJob
Scheduling"
);



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



do



{



printf("\n
Enter the number of Process(n>2):"
);



scanf("%d",&n);



}while(n<2);



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



{



printf("\nEnter
the CPU Burst Time of process %d:"
,i);



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



a[i]=i;



}



do



{



printf("\n\nSelect
the Scheduling Choice:"
);



printf("\n\t1.First
Come First Service(FCFS)"
);



printf("\n\t2.Shortest
Job First(SJF)"
);



printf("\n\t3.Priority\n\t4.Round
Robin"
);



printf("\n\t5.Exit\n\tEnter
Your Choice:"
);



scanf("%d",&ch);



switch(ch)



{



case
1:



printf("\n\n\t\tFirst
Come First Service(FCFS)"
);



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



m = 0;



line(c);



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



{




printf("P%d",i);




space(pd[i]);



}



printf("");



line(c);



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



{




printf("%d",m);




m = m + pd[i];




space(pd[i]+2);



}



printf("%d",m);



break;



case
2:



printf("\n\n\t\tShortest
Job First(SJF)"
);



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



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




pd1[i] = pd[i];




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




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




{




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




{




t = pd1[i]; pd1[i] = pd1[j]; pd1[j] = t;




t=a[i]; a[i]=a[j]; a[j]=t;




}









}




line(c);



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



{




printf("P%d",a[i]);




space(pd1[i]);



}



printf("");



line(c);



m=0;



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



{




printf("%d",m);




m = m + pd1[i];




space(pd1[i]+2);



}



printf("%d",m);



break;



case
3:



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



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



{




AB:




printf("\nEnter the Priority of process P%d:",i);




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




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




if((p[j]==p[i])(p[i]>n))




{




printf("\n\t!process P%d priority
is already exist OR >n"
,i);




goto AB;




}




pt[p[i]]=pd[i];




pri[p[i]]=i;



}



line(c);



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



{




printf("P%d",pri[i]);




space(pt[i]);



}



printf("");



line(c);



m=0;



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



{




printf("%d",m);




m = m + pt[i];




space(pt[i]+2);



}



printf("%d",m);



break;



case
4:



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



printf("\nEnter
the CPU Execution Time of each Process:"
);



scanf("%d",&ti);




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




if(max<pd[j])




max = pd[j];



max = max / 2;



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




pd2[i]=pd[i];



line(c);



m=k=0;



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




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




{




if(pd2[j]>0)




{




if(pd2[j]>=ti)




{




printf("P%d",j);




space(ti);




pd2[j]=pd2[j]-ti;




k++;




pd1[k]=ti;




}




else if(pd2[j]<ti)




{




printf("P%d",j);




space(ti-1);




k++;




pd1[k]=pd2[j];



pd2[j]=0;




}




}




}



printf("");



line(c);



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



{




printf("%d",m);




space(ti+2);




m = m +pd1[i];



}



break;



}



}while(ch<=4);



}




void

line(int c)



{



int i;



printf("\n\t");



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



printf("-");



printf("\n\t");



}




void

space(int c)



{



int i;



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



printf(" ");



}


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

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