Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j,at[20];
- printf("Enter total number of processes(maximum 20):");
- scanf("%d",&n);
- printf("\nEnter Process Arival Time & Burst Time\n");
- for(i=0;i<n;i++)
- {
- printf("P[%d]:",i+1);
- scanf("%d%d",&at[i],&bt[i]);
- }
- wt[0]=0; //waiting time for first process is 0
- //calculating waiting time
- for(i=1;i<n;i++)
- {
- wt[i]=0;
- for(j=0;j<i;j++)
- wt[i]+=bt[j];
- }
- printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time\tArivel Time");
- // arival time
- for(i=0;i<n;i++){
- temp = at[i];
- if(at[i]>at[i+1]){
- at[i] = at[i=1];
- at[i+1] = at[i]
- }
- }
- //calculating turnaround time
- for(i=0;i<n;i++)
- {
- tat[i]=bt[i]+wt[i];
- avwt+=wt[i];
- avtat+=tat[i];
- printf("\nP[%d]\t\t%d\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i],at[i]);
- }
- avwt/=i;
- avtat/=i;
- printf("\n\nAverage Waiting Time:%d",avwt);
- printf("\nAverage Turnaround Time:%d",avtat);
- printf("\n\n Thank You Mam \n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement