nht_cntt

RR

Dec 5th, 2016
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct _process
  5. {
  6.     char name[10];
  7.     float burstt;  
  8.     float remaint
  9.     //float arvt;  
  10.     float wt;      
  11.     float tat;      
  12.     //int priority
  13. }process;
  14.  
  15. main()
  16. {
  17.     process prc[15];
  18.     int numofprc,i=0,j=0;
  19.     float qtime,totbt=0,exetime;
  20.     printf("input the quantum time: ");
  21.     scanf("%f",&qtime);
  22.     printf("input the number of process: ");
  23.     scanf("%d",&numofprc);
  24.     printf("Input: - Name of process; - Burst time\n");
  25.     for(i=0;i<numofprc;i++)
  26.     {
  27.         scanf("%s%f",&prc[i].name,&prc[i].burstt);
  28.         prc[i].remaint = prc[i].burstt;
  29.         prc[i].wt = 0;
  30.         prc[i].tat = 0;
  31.         totbt+=prc[i].burstt;
  32.     }
  33.     while((int)totbt!=0)
  34.     {
  35.         if(i==numofprc)
  36.             i=0;
  37.        if(prc[i].remaint>qtime)
  38.             exetime = qtime;
  39.        else
  40.             exetime = prc[i].remaint;
  41.        prc[i].remaint-=exetime;
  42.        for(j=0;j<numofprc;j++)
  43.         {
  44.             if(j!=i&&prc[j].remaint!=0)
  45.                prc[j].wt+=exetime;
  46.         }
  47.         i++;
  48.         totbt-=exetime;
  49.     }
  50.     printf("Prc-Name||ExeTime||WTime||Tatime:\n");
  51.      for(i=0;i<numofprc;i++)
  52.     {
  53.         prc[i].tat = prc[i].burstt + prc[i].wt;
  54.         printf("%s\t   %.3f  %.3f  %.3f\n",prc[i].name,prc[i].burstt,prc[i].wt,prc[i].tat);
  55.     }
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment