manthanthakker40

OS-FCFS ALGO

Jul 26th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // operating systems ----FCFS algorithm---------
  2. #include<stdio.h>
  3. #include<conio.h>
  4. #include<math.h>
  5. void main()
  6. {
  7. int count=1,n=0,pid[100],at[100],et[100],ct[100],wt[100],tt[100],i=0,choice=1;
  8. float avgwt=0.0,avgtt=0.0;
  9. clrscr();
  10. while(choice==1)
  11. {
  12. printf("\nenter arrival time:-");
  13. scanf("%d",&at[i]);
  14. printf("\nenter execution time:-");
  15. scanf("%d",&et[i]);
  16. if(i==0)
  17. ct[i]=et[i];
  18. else
  19. ct[i]=ct[i-1]+et[i];
  20. wt[i]=ct[i]-(et[i]+at[i]);
  21. tt[i]=ct[i]-at[i];
  22. i++;
  23.  
  24. printf("more processes 1. yes 2. no ");
  25. scanf("%d",&choice);
  26. }
  27. printf("pid\tAT\tET\tCT\tWT\tTT\n");
  28. while(n!=i)
  29. {
  30. printf("%d\t",count++);
  31. printf("%d\t",at[n]);
  32. printf("%d\t",et[n]);
  33. printf("%d\t",ct[n]);
  34. printf("%d\t",wt[n]);
  35. printf("%d\n",tt[n]);
  36. n++;
  37. }
  38. n=0;
  39. while(n!=i)
  40. {
  41.  
  42. avgwt=wt[n]+avgwt;
  43. avgtt=tt[n]+avgtt;
  44. n++;
  45. }
  46.  
  47. printf("\n*******average waiting time is %f******\n",(avgwt/n));
  48. printf("*******average turnaound time is %f******\n",(avgtt/n));
  49.  
  50. getch();
  51. }
Advertisement
Add Comment
Please, Sign In to add comment