Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- struct process {
- char name[5];
- int burst;
- int prior;
- };
- int main() {
- int size;
- int warr[size + 1];
- int carr[size + 1];
- printf("\nEnter the number of processes : ");
- scanf("%d", & size);
- struct process arr[size];
- printf("\nEnter the process name, burst time, priority : \n");
- for (int i = 0; i < size; i++) {
- printf("\t-->\t");
- scanf("%s", arr[i].name);
- scanf("%d", &arr[i].burst);
- scanf("%d", &arr[i].prior);
- }
- int pos;
- struct process temp;
- int posarr[size + 1];
- for (int i = 0; i < size; i++) {
- posarr[i] = i;
- }
- for (int i = 0; i < size; i++) {
- pos = i;
- for (int j = i + 1; j < size; j++) {
- if (arr[j].prior < arr[pos].prior) {
- pos = j;
- }
- }
- temp = arr[i];
- arr[i] = arr[pos];
- arr[pos] = temp;
- }
- float waiting = 0, complete = 0;
- warr[0] = 0;
- for (int i = 0; i < size; i++) {
- warr[i + 1] = warr[i] + arr[i].burst;
- waiting += warr[i];
- }
- for (int i = 0; i < size; i++) {
- carr[i] = arr[i].burst + warr[i];
- complete += carr[i];
- }
- printf("\n");
- printf("------------------------------------------------------------------------------------------------------------------\n");
- printf("Process\t\tBurst Time\t\tPriority\t\tWaiting Time\t\tCompletion Time\n");
- for (int i = 0; i < size; i++) {
- printf("%s\t\t%d ms\t\t\t%d\t\t\t%d ms\t\t\t%d ms\n", arr[i].name,arr[i].burst,arr[i].prior, warr[i], carr[i]);
- }
- printf("------------------------------------------------------------------------------------------------------------------");
- printf("\nAverage Waiting Time : %.2f ms\n", waiting / size);
- printf("\nAverage Completion Time : %.2f ms\n", complete / size);
- }
Add Comment
Please, Sign In to add comment