ads

FCFS Scheduling Algorithm in C Programming

 FCFS Scheduling Algorithm in C Programming

FCFS : First Come First Serve

Criteria : Arrival Time

Mode : Non-preemptive


#include<stdio.h>
int main(){
    int at[15];
    int ct[15];
    int no,sum;
    int bt[15];
    int tat[15];
    int wt[15];
    int ttat=0;
    int twt=0;
    printf("Enter no of process : ");
    scanf("%d",&no);
    for(int i=0;i<no;i++){
        printf("Arival time of Process %d : ",i+1);
        scanf("%d",&at[i]);
         printf("Burst time of Process %d : ",i+1);
        scanf("%d",&bt[i]);
    }

    printf("\n\tProcess \t\t Arival time \t\t Burst time \n");
    for(int i=0;i<no;i++){
       printf("\n\t%d \t\t\t %d \t\t\t %d \n",i+1,at[i],bt[i]);
    }

    printf("------------------------------------------------------------------------------------------------\n");
    sum=at[0];
    for(int i=0;i<no;i++){
         sum=sum+bt[i];
         ct[i]=sum;
    }
    for(int i=0;i<no;i++){
         tat[i]=ct[i]-at[i];
         ttat=ttat+tat[i];
    }
     for(int i=0;i<no;i++){
         wt[i]=tat[i]-bt[i];
         twt=twt+wt[i];
    }
   
     printf("\nProcess \t Arival time \t Burst time \t completion time \t turnaround time \t waiting time\n");
     printf("------------------------------------------------------------------------------------------------");
    for(int i=0;i<no;i++){
       printf("\n%d \t\t %d \t\t %d \t\t %d \t\t\t %d \t\t\t %d \n",i+1,at[i],bt[i],ct[i],tat[i],wt[i]);
    }
    printf("------------------------------------------------------------------------------------------------\n");
    int awt=twt/no;
    int attat=ttat/no;
    printf("total turnaround time = %d \n",ttat);
    printf("average turnaround time = %d \n",attat);
    printf("total waiting time = %d \n",twt);
    printf("average waiting time = %d \n",awt);

    return 0;
}


Output :







 

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!