6/recent/ticker-posts

OS Shortest Job First 1

Write a C program to display the details of 2 processes given the process names, burst time of the processes and the arrival order of the processes. The process names are of type character, burst time and arrival time are of type integers.


Note: Display the process in ascending order  based on burst time.

Input and Output format :

Refer Sample Input and Output for inputs and formatting specifications.
Use printf("%s%60d%40d\n", p1.name, p1.cbt, p1.arrt); to display the details in the specified format. 
Use  "%s%30s%29s" to print the table header in  the specified format.

 

Sample Input and Output :
[All text in bold corresponds to input and the rest corresponds to output]

Enter the name of process 1
A
Enter the burst time of process 1
10
Enter the arrival order of process 1
2
Enter the name of process 2
B
Enter the burst time of process 2
20
Enter the arrival order of process 2
1
Process Details
Process Name       CPU Burst Time      Arrival Order
A                                         10                                2
B                                         20                                1


Answer:

#include<stdio.h>
int main()
{
    char pname[2];
    int ptime[2],porder[2],i=0,j=0;
    while(i!=2)
    {
        printf("Enter the name of process %d\n",(i+1));
        scanf("%s",&pname[i]);
        printf("Enter the burst time of process %d\n",(i+1));
        scanf("%d",&ptime[i]);
        printf("Enter the arrival order of process %d\n",(i+1));
        scanf("%d",&porder[i]);
        i=i+1;
    }
    printf("Process Details\n");
    printf("%s%30s%30s\n","Process Name","CPU Burst Time","Arrival Order");
    while(j!=2)
    {
        printf("%c%60d%40d\n",pname[j],ptime[j],porder[j]);
        j=j+1;
    }
    return 0;
}

Post a Comment

0 Comments