Thursday, August 27, 2009

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


No comments:

Post a Comment