Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- struct process
- {
- char pname[30];
- int btime,wtime,tatime;
- }arr[50];
- int main()
- {
- int n,i,ttatime=0,twtime=0,index;
- printf("Enter the number of processes:");
- scanf("%d",&n);
- for(i=1;i<=n;i++)
- {
- index=i-1;
- printf("Enter process #%d name:",i);
- scanf("%s",&arr[index].pname);
- printf("Enter burst time:");
- scanf("%d",&arr[index].btime);
- if(i==1)
- {
- arr[index].wtime=0;
- arr[index].tatime=arr[index].btime;
- }
- else
- {
- arr[index].wtime=arr[index-1].tatime;
- arr[index].tatime=arr[index].wtime+arr[index].btime;
- }
- ttatime+=arr[index].tatime;
- twtime+=arr[index].wtime;
- }
- for(i=1;i<=n;i++)
- {
- index=i-1;
- printf("PROCESS NAME:%s\nBURST TIME:%d\nWAITING TIME:%d\nTURNAROUND TIME:%d\n\n",arr[index].pname,arr[index].btime,arr[index].wtime,arr[index].tatime);
- }
- printf("Average waiting time:%f\nAverage turnaround time:%f\n",(float)twtime/n,(float)ttatime/n);
- return 0;
- }
- /*
- Output:
- [cse2a42@localhost ~]$ cc fcfs.c
- [cse2a42@localhost ~]$ ./a.out
- Enter the number of processes:3
- Enter process #1 name:A
- Enter burst time:5
- Enter process #2 name:B
- Enter burst time:10
- Enter process #3 name:C
- Enter burst time:15
- PROCESS NAME:A
- BURST TIME:5
- WAITING TIME:0
- TURNAROUND TIME:5
- PROCESS NAME:B
- BURST TIME:10
- WAITING TIME:5
- TURNAROUND TIME:15
- PROCESS NAME:C
- BURST TIME:15
- WAITING TIME:15
- TURNAROUND TIME:30
- Average waiting time:6.666667
- Average turnaround time:16.666667
- */
Add Comment
Please, Sign In to add comment