lab-7 (11/14)

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.5 kB
1
Indexable
Never
#include<stdio.h>
#include<stdlib.h>


int main()
{
     float IAT[30], AT[30], ST[30], TSB[30], WTQ[30], TSE[30];
    float TCSS[30], ITS[30], TST, avg_wt, TWQ, TIAT, POWC, POIS, TITS, avg_st, avg_iat, tiat, tst;
    IAT[0]=0.0;

    int wq=0,N=1,n,i,cnt=0,ch;
    printf("how many simulations do you want");
    scanf("%d",&n);

    printf("Enter the arrival time ?");
    for (i=1;i<n;i++){
    scanf("%f",&IAT[i]);
    tiat+=IAT[i];
    }
    printf("Enter the service time");
      for (i=0;i<n;i++){
    scanf("%f",&ST[i]);
    tst+=ST[i];
    }

    AT[0]=0.0; TSB[0]=0.0; WTQ[0]=0.0; TSE[0]=ST[0]; TCSS[0]=ST[0]; ITS[0]=0.0; TST=ST[0]; TIAT=0;

    printf("C.N\tIAT \t AT\t ST\t TSB\tWQT\t TSE\tTCSS\t ITS\n ");
    printf("\t%d \t0.2%f \t0.2%f \t0.2%f \t0.2%f \t0.2%f \t0.2%f \t0.2%f \t0.2%f \n", N,IAT[0],AT[0],ST[0],TSB[0],WTQ[0],TSE[0],TCSS[0],ITS[0]);

    for (i=1;i<n;i++){
        AT[i]=IAT[i]+AT[i-1];
        if ((ST[i-1]+ TSB[i-1])> AT[i]){
            TSB[i]= ST[i-1]+TSB[i-1];
        } else{
            TSB[i]=AT[i];
            WTQ[i]=TSB[i]-AT[i];
            if (WTQ[i]>0){
                wq+=WTQ[i];
                cnt++;
            }
            TSE[i]=TSB[i]+ST[i];
            TCSS[i]=ST[i]+WTQ[i];
            ITS[i]=TSB[i]-TSE[i-1];
            TWQ+=wq;
            TST=TST+ST[i];
            TIAT+=IAT[i];
            TITS+=ITS[i];
            N++;
           printf("\t%d \t  %6 \t0.2%f \t0.2%f \t0.2%f \t0.2%f \t0.2%f \t0.2%f \t0.2%f \n", N,IAT[i],AT[i],ST[i],TSB[i],WTQ[i],TSE[i],TCSS[i],ITS[i]);
        }
    }
    do {
        printf("Enter Average waiting time . Probability of wait of customer . Probability of idle server . Average service time . Average time between Arrival \n");

        scanf("%d",&ch);
        switch(ch){
        case 1:
            avg_wt=TWQ/(float)N;
            printf("Average waiting 0.2f",avg_wt);
            break;
        case 2:
             POWC=TIAT/((float)N-1);
            printf("Probability of wait of customer=%0.2f",POWC);
            break;
        case 3:
             POIS=TITS/TSE[i-1];
            printf("Probability of idle server =%0.2f",POIS);
            break;
        case 4:
             avg_st=tst/(float)N;
            printf("Average service time=%0.2f",avg_st);
            break;
        case 5:
             avg_iat=tiat /(float)(N-1);
            printf("Average inter arival time=%0.2f",avg_iat);
            break;

        default:
            printf("Invalid Choice");
            exit(0);
        }
    }
    while(1);
    return 0;
}