#include<stdio.h>
#include<conio.h>

typedef struct process{
    char pname[20];
    int at,bt,wt,ta,end;
}processes;

int main(){
    processes P[10];
    processes z[10];
    processes et[10];
    processes wt1[10];
    processes ta1[10];
    int a,b,n,x=0,st,y,w;
    float aveta,avewt,sumta=0,sumwt=0;
    printf("Process Scheduling Algorithm:\n");
    printf("SHORTEST JOB FIRST\n");
    printf("--------------------------------------\n");
    printf("Enter No. of Process: ");
    scanf("%d",&n);
    printf("\n");

    for(a=0;a<n;a++){
        printf("Enter Process Name P[%d]: ",a+1);
        scanf("%s",&P[a].pname);
    }

    printf("\n");

    for(a=0;a<n;a++){
        printf("Enter Arrival Time for P[%d]: ",a+1);
        scanf("%d",&P[a].at);
    }
    for(a=0; a<n; a++)
    {
        if(st > P[a].at)
        {
            st = P[a].at;

        }   
    }

    printf("\n");
    for(a=0;a<n;a++){
        printf("Enter Burst Time for P[%d]: ",a+1);
        scanf("%d",&P[a].bt);
    }
    printf("\n\n ========================================================================\n");
    printf("||\tPROCESS \t||\t ARRIVAL TIME \t||\t BURST TIME \t||\n");
    printf("||----------------------------------------------------------------------||\n");
    for(a=0;a<n;a++){
    printf("||\t P[%s] \t\t||\t  %d \t\t||\t  %d \t\t||\n",P[a].pname,P[a].at,P[a].bt);
    }
    printf(" ========================================================================\n");

    for(a=0;a<n;a++){
        z[a]=P[a];
        et[a]=P[a];
    }

    processes t;

    for(a=1;a<n;a++)
        for(b=0;b<n-a;b++){
            if(z[b].at > z[b+1].at){
                t = z[b];
                z[b] = z[b+1];
                z[b+1] = t;
            }
        }

    for(a=2;a<n;a++)
        for(b=1;b<n-a+1;b++){
            if(z[b].bt > z[b+1].bt){
                t = z[b];
                z[b] = z[b+1];
                z[b+1] = t;
            }
        }

    for(a=0;a<n;a++){
            x+=z[a].bt;
        }

    printf("\n GANTT CHART: \n");

        if(st>0){
        for(a=0;a<n;a++){
            if(st!=0){
                x=st+z[a].bt;
                printf("0\tIDLE\t%d\tP[%s]\t%d\t",st,z[a].pname,x);
                st=0;
                y=x;
                et[a].end=x;
                ta1[a].ta=et[a].end-z[a].at;
                wt1[a].wt=ta1[a].ta-z[a].bt;
            }
            else{
                y=y+z[a].bt;
                w=w+z[a].bt;
                w=y;
                printf("P[%s]\t%d\t",z[a].pname,y);
                y=w;
                et[a].end=y;
                ta1[a].ta=et[a].end-z[a].at;
                wt1[a].wt=ta1[a].ta-z[a].bt;
            }
        }
    }
    else{
        printf("0\t");
        for(a=0;a<n;a++){
                y=y+z[a].bt;
                w=w+z[a].bt;
                w=y;
                printf("P[%s]\t%d\t",z[a].pname,y);
                y=w;
                et[a].end=y;
                ta1[a].ta=et[a].end-z[a].at;
                wt1[a].wt=ta1[a].ta-z[a].bt;
            }

    }

    printf("\n\n ========================================================================\n");
    printf("||   PROCESS \t||   END TIME \t|| TURN AROUND T.\t|| WAITING TIME\t||\n");
    printf("||----------------------------------------------------------------------||\n");
    for(a=0;a<n;a++){
    printf("||  P[%s] \t||    %d \t||      %d \t\t||  %d \t\t|| \n",z[a].pname,et[a].end,ta1[a].ta,wt1[a].wt);
    sumta+=ta1[a].ta;
    sumwt+=wt1[a].wt;
    }
    printf(" =========================================================================\n");
    aveta=sumta/n;
    avewt=sumwt/n;
    printf("\n Average Turn Around Time: %.2f",aveta);
    printf("\n Average Waiting Time: %.2f",avewt);
getch();
return 0;
}
  1. whby do you have to convert it?
  2. why can't you convert it?
  3. are there any error messages?
  4. what is the platform (windows/linux)?
  5. what compiler are you using?
  6. are you having any specific problems?
  7. what does the code do?

You want help but you can't be bothered to provide any details. The code is uncommented and I strongly suspect it was written by an engineer (based on the non-descriptive variable names).

At least, I am assuming you want help. Surely you wouldn't just post your code and expect someone here to convert it for you.

There is no need to convert it to C. It is already C code. But it uses conio.h, which is a non-standard C extension that is not supported by all compilers.

Remove the include for conio and remove the call to getch at the end and you're left with standard, portable C code.

nevermind guys ive done it myself thanks for the reply....

W. A. P to accept a distance in mitter an convert sentimitter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.