Last active
September 21, 2018 07:54
-
-
Save mihirsam/35b4f60e38bdfc68a6c6927a97552697 to your computer and use it in GitHub Desktop.
First Come First Serve Algorithm | Gantt Chart | Waiting Time | Turn Around Time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by xenon on 18/9/18. | |
// | |
#include<stdio.h> | |
#include<stdbool.h> | |
struct Input | |
{ | |
char ProcessId[100]; | |
int at, bt; | |
}; | |
void input(int num, struct Input *process) | |
{ | |
printf("\n\nEnter Details Of Process %d: ", num); | |
printf("\nProcess Name : "); | |
scanf("%s", process->ProcessId); | |
printf("Enter Arrival Time : "); | |
scanf("%d", &process->at); | |
printf("Enter Burst Time : "); | |
scanf("%d", &process->bt); | |
} | |
int main() | |
{ | |
struct Input obj[100]; | |
int choice, processNum, prevTime = 0; | |
printf("\nEnter The Number Of Process : "); | |
scanf("%d", &processNum); | |
for(int i=0; i<processNum; i++) | |
{ | |
input(i, &obj[i]); | |
} | |
while(true) | |
{ | |
printf("\n1. Gantt Chart\n2. Waiting Time\n3. Turn Around Time\n4. Exit\nChoice : "); | |
scanf("%d", &choice); | |
if (choice == 1) | |
{ | |
printf("\n\nGantt Chart:\n"); | |
for(int i=0; i<processNum; i++) | |
{ | |
if (obj[i].at >= prevTime) | |
{ | |
printf("%d", obj[i].at); | |
for(int j=0; j<obj[i].bt; j++) | |
{ | |
printf("*"); | |
} | |
prevTime = prevTime + obj[i].bt; | |
} | |
else | |
{ | |
printf("%d", prevTime); | |
for(int j=0; j<obj[i].bt; j++) | |
{ | |
printf("*"); | |
} | |
prevTime = prevTime + obj[i].bt; | |
} | |
} | |
printf("%d\n\n", prevTime); | |
prevTime = 0; | |
} | |
else if(choice == 2) | |
{ | |
printf("\n\nWaiting Time:\nProcess Number\t\tWaiting Time\n"); | |
for(int i=0; i<processNum; i++) | |
{ | |
if (obj[i].at >= prevTime) | |
{ | |
printf("%s\t\t\t%d\n", obj[i].ProcessId, 0); | |
prevTime = prevTime + obj[i].bt; | |
} | |
else | |
{ | |
printf("%s\t\t\t%d\n", obj[i].ProcessId, prevTime-obj[i].at); | |
prevTime = prevTime + obj[i].bt; | |
} | |
} | |
prevTime = 0; | |
} | |
else if(choice == 3) | |
{ | |
printf("\n\nTurn Around Time:\nProcess Number\t\tTurn Around Time\n"); | |
for(int i=0; i<processNum; i++) | |
{ | |
if (obj[i].at >= prevTime) | |
{ | |
printf("%s\t\t\t%d\n", obj[i].ProcessId, obj[i].bt); | |
prevTime = prevTime + obj[i].bt; | |
} | |
else | |
{ | |
printf("%s\t\t\t%d\n", obj[i].ProcessId, prevTime-obj[i].at+obj[i].bt); | |
prevTime = prevTime + obj[i].bt; | |
} | |
} | |
prevTime = 0; | |
} | |
else if(choice == 4) | |
{ | |
break; | |
} | |
else | |
{ | |
printf("\nInvalid Input!\nTry Again\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment