SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
Hitesh Patel
 
structure and union
structure and unionstructure and union
structure and union
student
 

Tendances (20)

RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12Bca sem 6 php practicals 1to12
Bca sem 6 php practicals 1to12
 
structure and union
structure and unionstructure and union
structure and union
 
FUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPTFUNCTIONS IN c++ PPT
FUNCTIONS IN c++ PPT
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Object Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical FileObject Oriented Programming Using C++ Practical File
Object Oriented Programming Using C++ Practical File
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Python Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String MethodsPython Programming Essentials - M8 - String Methods
Python Programming Essentials - M8 - String Methods
 
File and directories in python
File and directories in pythonFile and directories in python
File and directories in python
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Array in c++
Array in c++Array in c++
Array in c++
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
String matching algorithms
String matching algorithmsString matching algorithms
String matching algorithms
 
Php array
Php arrayPhp array
Php array
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
C Programming Project
C Programming ProjectC Programming Project
C Programming Project
 
Enums in c
Enums in cEnums in c
Enums in c
 

En vedette

Cpu scheduling algorithms simulation using java
Cpu scheduling algorithms simulation using javaCpu scheduling algorithms simulation using java
Cpu scheduling algorithms simulation using java
jsivasrinivas
 
First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)First-Come-First-Serve (FCFS)
First-Come-First-Serve (FCFS)
nikeAthena
 
Fcfs scheduling
Fcfs schedulingFcfs scheduling
Fcfs scheduling
myrajendra
 
Computer concepts- Mohammadali & Tausif
Computer concepts- Mohammadali & TausifComputer concepts- Mohammadali & Tausif
Computer concepts- Mohammadali & Tausif
tausif ghodesawar
 
Io techniques & its types
Io techniques & its typesIo techniques & its types
Io techniques & its types
Nehal Naik
 

En vedette (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
 

Plus de One97 Communications Limited

Plus de 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(); }