#include<stdio.h>
int main( )
{
int n;
printf ( "Enter number of processes: " ) ; int at[ n] , bt[ n] , ct[ n] , tat[ n] , wt[ n] , rt[ n] ;
for ( int i= 0 ; i< n; i++ )
{
printf ( "Enter the arrival and burst time for p%d : " , i
+ 1 ) ; scanf ( "%d %d" ,& at
[ i
] ,& bt
[ i
] ) ;
}
for ( int i= 0 ; i< n- 1 ; i++ )
{
for ( int j= i+ 1 ; j< n; j++ )
{
if ( at[ i] > at[ j] )
{
int temp;
temp= at[ i] ; at[ i] = at[ j] ; at[ j] = temp;
temp= bt[ i] ; bt[ i] = bt[ j] ; bt[ j] = temp;
}
}
}
//ct
ct[ 0 ] = at[ 0 ] + bt[ 0 ] ;
for ( int i= 1 ; i< n; i++ )
{
if ( ct[ i- 1 ] < at[ i] )
ct[ i] = at[ i] + bt[ i] ;
else
ct[ i] = at[ i- 1 ] + bt[ i] ;
}
//tat wt rt
for ( int i= 0 ; i< n; i++ )
{
tat[ i] = ct[ i] - at[ i] ;
wt[ i] = tat[ i] - bt[ i] ;
rt[ i] = wt[ i] ;
}
printf ( "\n P\t AT\t BT\t CT\t TAT\t WT\t RT\n " ) ; for ( int i= 0 ; i< n; i++ )
printf ( "P%d\t %d\t %d\t %d\t %d\t %d\t %d\n " , i
+ 1 , at
[ i
] , bt
[ i
] , ct
[ i
] , tat
[ i
] , wt
[ i
] , rt
[ i
] ) ; }
I2luY2x1ZGU8c3RkaW8uaD4KaW50IG1haW4oKQp7CglpbnQgbjsKCXByaW50ZigiRW50ZXIgbnVtYmVyIG9mIHByb2Nlc3NlczogIik7CglzY2FuZigiJWQiLCZuKTsKCWludCBhdFtuXSxidFtuXSxjdFtuXSx0YXRbbl0sd3Rbbl0scnRbbl07Cglmb3IoaW50IGk9MDtpPG47aSsrKQoJewoJCXByaW50ZigiRW50ZXIgdGhlIGFycml2YWwgYW5kIGJ1cnN0IHRpbWUgZm9yICBwJWQgOiAiLGkrMSk7CgkJc2NhbmYoIiVkICVkIiwmYXRbaV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