program for FIFO ALGORITHM using c-languge


FIFO ALGORITHM
#include<stdio.h>
#include<conio.h>
struct process
{
char name[20];
int at,bt;
}q[20],temp;
main()
{
int f,r,ft,i,j,n,wt,tat;
float awt=0;
clrscr();
printf("enter the number of processes:");
scanf("%d",&n);
for(r=0;r<n;r++)
{
printf("\n enter process name,arrival time and burest time:");
scanf("%s%d%d",&q[r].name,&q[r].at,&q[r].bt);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(q[i].at>q[j].at)
{
temp=q[i];
q[i]=q[j];
}q[j]=temp;
printf("\n\n\t\t*********fcfs*************");
printf("\n.................................");
printf("....................................");
printf("\n process name arrival time burest time");
printf("finish time turn around tim waiting time");
printf("\n.................................");
printf("......................................");
wt=0;
ft=q[0].at;
tat=0;
for(f=0;f<n;f++)
{
wt=ft-q[f].at;
if(wt<0)
wt=0;
ft=ft+q[f].bt;
tat=ft-q[f].at;
awt=awt+wt;
printf("\t\n%-14s%-11d",q[f].name,q[f].at);
printf("%-11d%-15d%-8d%-11d",q[f].bt,ft,tat,wt);
}
printf("\n.........................");
printf("..............................");
awt=awt/n;
printf("\n\n\t\t average waiting time=%5.4f",awt);
}

No comments:

Post a Comment