C Program for Round Robin Scheduling Algorithm is always one of the best.It’s was, one of the most demanding, even now. So, this article is all about writing a C Program for Round Robin Scheduling Algorithm.
The following algorithm,modified and tried make as simple as possible.
The main terms used in Round Robin Scheduling Algorithm :
Waiting time
The sum of the time periods spent in waiting in the ready queue.
Process time
The time consumed by a process to execute.
#include<stdio.h> #include<string.h> void main() { char process[10][5]; int et[10],waitingtime[10],timer=3,count,processing_time[10],rt,i,j,total_waiting_time=0,t,n=5,found=0,m; float avgwt; for(i=0;i<n;i++) { printf("enter the process name : "); scanf("%s",&process[i]); printf("enter the processing time : "); scanf("%d",&processing_time[i]); } m=n; waitingtime[0]=0; i=0; do { if(processing_time[i]>timer) { rt=processing_time[i]-timer; strcpy(process[n],process[i]); processing_time[n]=rt; et[i]=timer; n++; } else { et[i]=processing_time[i]; } i++; waitingtime[i]=waitingtime[i-1]+et[i-1]; }while(i<n); count=0; for(i=0;i<m;i++) { for(j=i+1;j<=n;j++) { if(strcmp(process[i],process[j])==0) { count++; found=j; } } if(found!=0) { waitingtime[i]=waitingtime[found]-(count*timer); count=0; found=0; } } for(i=0;i<m;i++) { total_waiting_time+=waitingtime[i]; } avgwt=(float)total_waiting_time/m; for(i=0;i<m;i++) { printf("n%st%dt%d",process[i],processing_time[i],waitingtime[i]); } printf("ntotal waiting time %dn",total_waiting_time); printf("total avgtime %f",avgwt); }