//[ Issue Fix ] How to fix errors in FCFS Scheduling Program in C programming?

[ Issue Fix ] How to fix errors in FCFS Scheduling Program in C programming?

Logical error in FCFS Scheduling Algorithm . How to fix ? Below is the simple program to implement the FCFS algorithm.

C program for FCFS scheduling Algorithm ( Implementation of logic )

// experiment no:1 for checking the turnaround time and average of FCFS algoritm.Devloped and compiled by Nirmal Ram . copyrighted 2018

#include<stdio.h>
int main()
{
int limit,arrive[20],burst[20],i,completetime[100],turnaround[100],waiting[100],avg[100];
printf("\n\nChecking Turnaround Time and Average : Developed & compiled by Nirmal Ram\n========================================================================\n\n");
printf("Enter the number of process : ");
scanf("%d",&limit);
printf("\nEnter the Arrival time and Burst time of processes :\n=================================================\n ");
for(i=1;i<=limit;i++) // set your values
{
printf("\nArrival Time of process %d :" , i);
scanf("%d",&arrive[i]);
printf("\nburst time of process %d : ",i);
scanf("%d",&burst[i]);
}
printf("\n\n Arrival Time and Burst Time addded succesfully ! \n=======================================================\n\n");
for(i=1 ; i<=limit;i++)
{
printf("Process %d : Arival time : %d Burst Time : %d \n\n",i,arrive[i],burst[i]); // display inputs
}
printf("/n Calculating.........Completion Time , Turn Around Time and Waiting Time\n\n");
printf(" --------------------------------------------------------------------------------------------------------------\n");
completetime[1]=burst[1];
for (i=1;i<=limit;i++)
{
completetime[i+1]=completetime[i]+burst[i+1];
turnaround[i]=completetime[i]-arrive[i];
waiting[i]=turnaround[i]-burst[i];
printf("process %d | Arrival Time : %d | Burst Time : %d | Completion Time : %d | Turnaround Time : %d | Waiting time : %d |\n\n",i,arrive[i],burst[i],completetime[i],turnaround[i],waiting[i]);
}
printf("\n\nAverage Waiting Time calculating.........................\n\n");
avg[0]=0;
for (i=1;i<=limit;i++)
{
avg[i]=waiting[i]+avg[i-1];
}
printf("\n\n Average Time is Calculated : %d ",avg[limit]/limit);
printf("\n\n Programm is succesfully completed !! congratulation !\n=======================================================\n\nDeveloped and compiled : Nirmal Ram\ncompany:pineapplem3 Inc\n\n\n");

}

 

 

C program to Fix the error due to Arrival time in FCFS algorithm ( Improved Version of Above code )

#include <stdio.h>
void main()
{
int i=0,limit,min,arrive[10],burst[10],completetime[10],turnaround[10],waiting[10],b[10],p[10],j;
float avwt=0.0,avta=0.0;
printf("\n\nChecking Turnaround Time and Average of FCFS scheduling | from : pineapplem3.com \n=============================================================================================\n\n");
printf("Enter the number of process : ");
scanf("%d",&limit);
printf("\nEnter the Arrival time and Burst time of processes :\n=================================================\n\n ");
for(i=0;i<limit;i++)
{
printf("\nEnter the arrival time of process %d : ",(i+1));
scanf("%d",&arrive[i]);
printf("\nEnter the burst time of process %d : ",(i+1));
scanf("%d",&burst[i]);
p[i]=i+1;
}
printf("\n\n Arrival Time and Burst Time addded succesfully ! \n=======================================================\n\n");
for (i=0;i<limit;i++)
{ min=i;
for(j=i+1;j<limit;j++)
if(arrive[j]<arrive[min])
min=j;
int temp1=arrive[i];
int temp2=burst[i];
int temp3=p[i];
arrive[i] = arrive[min];
burst[i] = burst[min];
p[i]=p[min];
arrive[min]=temp1;
burst[min]=temp2;
p[min]=temp3;
}
printf("calculating Completion time , Turnaround time , waiting Time ..........................Done.\n\n");

completetime[0]=burst[0]+arrive[0];
for(j=0;j<limit;j++)
{
printf("\n Process %d: ",p[j]);
if(completetime[j]<arrive[j+1])
completetime[j+1]=burst[j+1]+arrive[j+1];
else
completetime[j+1]=burst[j+1]+completetime[j];
turnaround[j]=completetime[j]-arrive[j];
waiting[j]=turnaround[j]-burst[j];
printf("\tcompletion Time of %d\t |",completetime[j]);
printf("\tTurnaround Time of %d\t |",turnaround[j]);
printf("\twaiting Time of %d\t |\n",waiting[j]);
}
printf("\n\nCalculating Average waiting time and Turnaround time..........................Done.\n\n=========================================================================\n\n");
for(i=0;i<limit;i++)
{
avwt=avwt+waiting[i];
avta=avta+turnaround[i];
}
avwt=avwt/3;
avta=avta/3;
printf("average turn around time of %d processes = %f\n ",limit,avta);
printf("average waiting time of %d processes = %f\n",limit,avwt);
printf("\n\nProgram succesfully completed......Congratulation!\n From: Pineapplem3.com\n\nProgram Ends.\n\n\n");
}


 

If error still persist share in the Discussion section below with a screenshot. you can find more discussion below. 

Nirmal Ram is the Founder & CEO of pineapplem3 Inc , Co-Founder of Gene Ai Foundation & Researcher in Artificial Intelligence & Machine Learning. Born on April 1998 in Kerala ,India . He's a passionate Programmer & Developer . He believed in his work with ethics and filled with confidence. His start-up journey begins on 2016 , Skilled in handling 10+ computer Languages .He's Hard worker , Freelancer & Instructor . He started earning with his Freelancing Journey since 2017. brought up pineapplem3.com worth about $67.16 in 2016.