Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct process
- {
- char name[5];
- int burst;
- };
- int
- main ()
- {
- int size;
- int warr[size + 1];
- int carr[size+1];
- printf ("\nEnter the number of processes : ");
- scanf ("%d", &size);
- struct process arr[size];
- struct process Process;
- printf ("\nEnter the process name and burst time : \n");
- for (int i = 0; i < size; i++)
- {
- printf("\t-->\t");
- scanf ("%s", Process.name);
- scanf ("%d", &Process.burst);
- arr[i] = Process;
- }
- int pos,temp;
- int posarr[size+1];
- for(int i=0;i<size;i++){
- posarr[i]=i;
- }
- for(int i=0;i<size;i++)
- {
- pos=i;
- for(int j=i+1;j<size;j++)
- {
- if(arr[j].burst<arr[pos].burst)
- {
- pos=j;
- }
- }
- temp=arr[i].burst;
- arr[i].burst=arr[pos].burst;
- arr[pos].burst=temp;
- temp=posarr[i];
- posarr[i]=posarr[pos];
- posarr[pos]=temp;
- }
- float waiting = 0,complete=0;
- warr[0] = 0;
- for(int i=0;i<size;i++){
- warr[i+1] = warr[i]+arr[i].burst;
- waiting += warr[i];
- }
- for(int i=0;i<size;i++){
- carr[i] = arr[i].burst + warr[i];
- complete+=carr[i];
- }
- printf("Process\tBurst Time\tWaiting Time\tCompletion Time\n");
- for(int i=0;i<size;i++){
- printf("%s\t%d ms\t\t%d ms\t\t%d ms\n",arr[posarr[i]].name,arr[i].burst,warr[i],carr[i]);
- }
- printf ("\nAverage Waiting Time : %.2f ms", waiting / size);
- printf ("\nAverage Completion Time : %.2f ms\n", complete / size);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement