Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //FCFS
- #include<stdio.h>
- #include<string.h>
- int sort(int ps[],int at[],int bt[],int n)
- {
- int j,k,temp;
- for(j=1;j<n;j++){
- for(k=1;k<n;k++){
- if(at[k]>at[k+1]){
- temp=at[k];
- at[k]=at[k+1];
- at[k+1]=temp;
- temp=ps[k];
- ps[k]=ps[k+1];
- ps[k+1]=temp;
- temp=bt[k];
- bt[k]=bt[k+1];
- bt[k+1]=temp;
- }
- }
- }
- }
- int main()
- {
- int ps[50],at[50],bt[50],n,i,end=0;
- printf("Input Number of Total Process\n");
- scanf("%d",&n);
- printf("Input Respectivly- Process > Arrival Time > Brust Time\nLike, 1 3 5\n");
- for(i=1;i<=n;i++){
- scanf("%d %d %d",&ps[i],&at[i],&bt[i]); // Input Process, At, Bt
- }
- sort(ps,at,bt,n); // Sort array accordingly Arrival time
- printf("Process - Start_Time - End_Time - Wating_Time - Respons_Time\n");
- for(i=1;i<=n;i++){
- if(end>=at[i]){
- printf("P%d %d %d %d %d\n",ps[i],end,end+bt[i],end+bt[i]-at[i],end-at[i]); // Print Process
- end= end+bt[i];
- }
- else{
- printf("Idol %d %d\n",end,end+at[i]); // Print Idol
- end= end+at[i];
- i--;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement