SlideShare a Scribd company logo
1 of 4
#include<stdio.h> 
#include<conio.h> 
#include<string.h> 
int n,Bu[20],Twt,Ttt,A[10],Wt[10],w; 
float Awt,Att; 
char pname[20][20],c[20][20]; 
void Getdata(); 
void Gantt_chart(); 
void Calculate(); 
void fcfs(); 
void Getdata() 
{ 
int i; 
printf("n Enter the number of processes: "); 
scanf("%d",&n); 
for(i=1;i<=n;i++) 
{ 
fflush(stdin); 
printf(" Enter the process name: "); 
scanf("%s",&pname[i]); 
printf(" Enter the Arrival Time for Process %s = ",pname[i]); 
scanf("%d",&A[i]); 
printf(" Enter The BurstTime for Process %s = ",pname[i]); 
scanf("%d",&Bu[i]); 
} 
} 
void Gantt_chart() 
{ 
int i; 
printf("nnttFIRST COME FIRST SERVED ALGORITHM"); 
printf("nttt GANTT CHARTn"); 
printf("nt|--------------------------------------------|n"); 
printf("t|"); 
for(i=1;i<=n;i++) 
printf(" %s |",pname[i]); 
printf("nt|--------------------------------------------|n"); 
printf(" "); 
for(i=1;i<=n;i++) 
printf("%d ",Wt[i]); 
printf("%d",Wt[n]+Bu[n]);
} 
void Calculate() 
{ 
int i; 
Wt[1]=0; 
for(i=2;i<=n;i++) 
{ 
Wt[i]=Bu[i-1]+Wt[i-1]; 
} 
for(i=1;i<=n;i++) 
{ 
Twt=Twt+(Wt[i]-A[i]); 
Ttt=Ttt+((Wt[i]+Bu[i])-A[i]); 
} 
Att=(float)Ttt/n; 
Awt=(float)Twt/n; 
printf("n Average Turn around time = %3.2f ms n",Att); 
printf(" Average Waiting Time = %3.2f ms",Awt); 
} 
void fcfs() 
{ 
int i,j,temp, temp1; 
Twt=0; 
Ttt=0; 
for(i=1;i<=n;i++) 
{ 
for(j=i+1;j<=n;j++) 
{ 
if(A[i]>A[j]) 
{ 
temp=Bu[i]; 
temp1=A[i]; 
Bu[i]=Bu[j]; 
A[i]=A[j]; 
Bu[j]=temp; 
A[j]=temp1; 
strcpy(c[i],pname[i]); 
strcpy(pname[i],pname[j]); 
strcpy(pname[j],c[i]); 
} 
}
} 
Calculate(); 
Gantt_chart(); 
} 
void main() 
{ 
clrscr(); 
Getdata(); 
fcfs(); 
getch(); 
}
OUTPUT

More Related Content

What's hot

Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of LanguageDipankar Boruah
 
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...Mahbubur Rahman
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab filesNitesh Dubey
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Alamgir Hossain
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesOmprakash Chauhan
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsSreedhar Chowdam
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functionssinhacp
 
Raster scan system
Raster scan systemRaster scan system
Raster scan systemMohd Arif
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture NotesFellowBuddy.com
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESVENNILAV6
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Akila Krishnamoorthy
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04Spy Seat
 

What's hot (20)

Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of Language
 
MYSQL.ppt
MYSQL.pptMYSQL.ppt
MYSQL.ppt
 
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...
Constraint Satisfaction Problem (CSP) : Cryptarithmetic, Graph Coloring, 4- Q...
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 
Python Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, ExceptionsPython Programming: Lists, Modules, Exceptions
Python Programming: Lists, Modules, Exceptions
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Linear time sorting algorithms
Linear time sorting algorithmsLinear time sorting algorithms
Linear time sorting algorithms
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Compiler Design Lecture Notes
Compiler Design Lecture NotesCompiler Design Lecture Notes
Compiler Design Lecture Notes
 
MySQL Functions
MySQL FunctionsMySQL Functions
MySQL Functions
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)
 
Loops PHP 04
Loops PHP 04Loops PHP 04
Loops PHP 04
 
And or graph
And or graphAnd or graph
And or graph
 

Viewers also liked

Viewers also liked (20)

Cpu scheduling algorithms simulation using java
Cpu scheduling algorithms simulation using javaCpu scheduling algorithms simulation using java
Cpu scheduling algorithms simulation using java
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)
 
Fcfs scheduling
Fcfs schedulingFcfs scheduling
Fcfs scheduling
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
CPU scheduling algorithms in OS
CPU scheduling algorithms in OSCPU scheduling algorithms in OS
CPU scheduling algorithms in OS
 
FCFS scheduling OS
FCFS scheduling OSFCFS scheduling OS
FCFS scheduling OS
 
CPU Scheduling algorithms
CPU Scheduling algorithmsCPU Scheduling algorithms
CPU Scheduling algorithms
 
First Come First Serve
First Come First ServeFirst Come First Serve
First Come First Serve
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
Computer concepts- Mohammadali & Tausif
Computer concepts- Mohammadali & TausifComputer concepts- Mohammadali & Tausif
Computer concepts- Mohammadali & Tausif
 
Fcfs
FcfsFcfs
Fcfs
 
Protect Folders without using any Software
Protect Folders without using any SoftwareProtect Folders without using any Software
Protect Folders without using any Software
 
Computer Forensics
Computer ForensicsComputer Forensics
Computer Forensics
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
 
Io techniques & its types
Io techniques & its typesIo techniques & its types
Io techniques & its types
 
Backtrack
BacktrackBacktrack
Backtrack
 
Blue eye technology
Blue eye technology Blue eye technology
Blue eye technology
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 

More from One97 Communications Limited

WAP to invoke constructors using super keyword in java
WAP to invoke constructors using super keyword in javaWAP to invoke constructors using super keyword in java
WAP to invoke constructors using super keyword in javaOne97 Communications Limited
 
WAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in javaWAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in javaOne97 Communications Limited
 
How to achieve multiple inheritances by using interface in java
How to achieve multiple inheritances by using interface in java How to achieve multiple inheritances by using interface in java
How to achieve multiple inheritances by using interface in java One97 Communications Limited
 
WAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in javaWAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in javaOne97 Communications Limited
 
WAP to initialize different objects with different values in java
WAP to initialize different objects with different values in javaWAP to initialize different objects with different values in java
WAP to initialize different objects with different values in javaOne97 Communications Limited
 

More from One97 Communications Limited (20)

Er. Model Of Hospital Management
Er. Model Of Hospital ManagementEr. Model Of Hospital Management
Er. Model Of Hospital Management
 
Financial
FinancialFinancial
Financial
 
Railway
RailwayRailway
Railway
 
Library
LibraryLibrary
Library
 
Neural Interfacing
Neural Interfacing Neural Interfacing
Neural Interfacing
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Topology
TopologyTopology
Topology
 
WAP to invoke constructors using super keyword in java
WAP to invoke constructors using super keyword in javaWAP to invoke constructors using super keyword in java
WAP to invoke constructors using super keyword in java
 
WAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in javaWAP to find out whether the number is prime or not in java
WAP to find out whether the number is prime or not in java
 
Overriding abstract in java
Overriding abstract in javaOverriding abstract in java
Overriding abstract in java
 
How to achieve multiple inheritances by using interface in java
How to achieve multiple inheritances by using interface in java How to achieve multiple inheritances by using interface in java
How to achieve multiple inheritances by using interface in java
 
Method overriding in java
Method overriding in javaMethod overriding in java
Method overriding in java
 
WAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in javaWAP to implement inheritance and overloading methods in java
WAP to implement inheritance and overloading methods in java
 
program on Function overloading in java
program on  Function overloading in javaprogram on  Function overloading in java
program on Function overloading in java
 
Program on usage of Final keyword in java
Program on usage of  Final keyword in javaProgram on usage of  Final keyword in java
Program on usage of Final keyword in java
 
WAP to initialize different objects with different values in java
WAP to initialize different objects with different values in javaWAP to initialize different objects with different values in java
WAP to initialize different objects with different values in java
 
Conversion of data types in java
Conversion of data types in javaConversion of data types in java
Conversion of data types in java
 
Constructor Overloading in java
Constructor Overloading in javaConstructor Overloading in java
Constructor Overloading in java
 
programming for Calculator in java
programming for Calculator in javaprogramming for Calculator in java
programming for Calculator in java
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
 

Fcfs Cpu Scheduling With Gantt Chart

  • 1. #include<stdio.h> #include<conio.h> #include<string.h> int n,Bu[20],Twt,Ttt,A[10],Wt[10],w; float Awt,Att; char pname[20][20],c[20][20]; void Getdata(); void Gantt_chart(); void Calculate(); void fcfs(); void Getdata() { int i; printf("n Enter the number of processes: "); scanf("%d",&n); for(i=1;i<=n;i++) { fflush(stdin); printf(" Enter the process name: "); scanf("%s",&pname[i]); printf(" Enter the Arrival Time for Process %s = ",pname[i]); scanf("%d",&A[i]); printf(" Enter The BurstTime for Process %s = ",pname[i]); scanf("%d",&Bu[i]); } } void Gantt_chart() { int i; printf("nnttFIRST COME FIRST SERVED ALGORITHM"); printf("nttt GANTT CHARTn"); printf("nt|--------------------------------------------|n"); printf("t|"); for(i=1;i<=n;i++) printf(" %s |",pname[i]); printf("nt|--------------------------------------------|n"); printf(" "); for(i=1;i<=n;i++) printf("%d ",Wt[i]); printf("%d",Wt[n]+Bu[n]);
  • 2. } void Calculate() { int i; Wt[1]=0; for(i=2;i<=n;i++) { Wt[i]=Bu[i-1]+Wt[i-1]; } for(i=1;i<=n;i++) { Twt=Twt+(Wt[i]-A[i]); Ttt=Ttt+((Wt[i]+Bu[i])-A[i]); } Att=(float)Ttt/n; Awt=(float)Twt/n; printf("n Average Turn around time = %3.2f ms n",Att); printf(" Average Waiting Time = %3.2f ms",Awt); } void fcfs() { int i,j,temp, temp1; Twt=0; Ttt=0; for(i=1;i<=n;i++) { for(j=i+1;j<=n;j++) { if(A[i]>A[j]) { temp=Bu[i]; temp1=A[i]; Bu[i]=Bu[j]; A[i]=A[j]; Bu[j]=temp; A[j]=temp1; strcpy(c[i],pname[i]); strcpy(pname[i],pname[j]); strcpy(pname[j],c[i]); } }
  • 3. } Calculate(); Gantt_chart(); } void main() { clrscr(); Getdata(); fcfs(); getch(); }