All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Tuesday 5 August 2014

FCFS Program

#include<iostream.h>
#include<conio.h>
void main()
{
    int i, n, process[10], total=0, wtime[10], ptime[10],turntotal[10];
    float avg=0;
    clrscr();
    cout<<"\nEnter number of Processes:";
    cin>>n;
    for(i=0;i<n;i++)
    {
cout<<"Enter Process "<<i+1<<" ID:";
cin>>process[i];
cout<<"Enter Process "<<i+1<<" Burst Time:";
cin>>ptime[i];
    }
    wtime[0]=0;
    for(i=1;i<n;i++)
    {
wtime[i]=wtime[i-1]+ptime[i-1];
total=total+wtime[i];
    }
    for(i=0;i<n;i++)
    {
    turntotal[i]=ptime[i]+wtime[i];
    }
    avg=(float)total/n;
    cout<<"\nP_ID\t P_TIME\t W_TIME\t TURN_Time\n";
    for(i=0;i<n;i++)
cout<<process[i]<<"\t"<<ptime[i]<<"\t"<<wtime[i]<<"\t"<<turntotal[i]<<"\n";
    cout<<"\nTotal Waiting Time:"<<total;
    cout<<"\nAverage Waiting Time:"<<avg;
    getch();
}

No comments:

Post a Comment