Вы находитесь на странице: 1из 9

#include<stdio.

h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#define SIZE 50
float w[SIZE],t[SIZE],tavg,wavg,avg=0.0,avg1=0.0;
int b[SIZE],b1[SIZE],i,n,ch,ch1;

void main()
{
clrscr();
printf("\n\t******Scheduling Algorithms******\t\n");
do
{
printf(" 1.Enter Input Values\n 2.Display Input Table\n 3.Turn around time\n 4.W
aiting Time\n 5.GANNT CHART\n 6.EXIT");
printf("Enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1 : printf("Enter the number of processes:");
scanf("%d",&n);
printf("\nEnter the processes burst times\n");
for(i=0;i<n;i++)
{
printf("Enter the burst time of process%d:",i);
scanf("%d",&b1[i]);
}
for(i=0;i<n;i++)
{
b[i]=b1[i];
}
for(i=0;i<n;i++)
for(int j=0;j<n;j++)
if(b[i]<b[j])
{
int temp=b[i];
b[i]=b[j];
b[j]=temp;
}
break;
case 2: printf("The Input table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b1[i]);
}
printf("The sorted table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b[i]);
}
break;

case 3: t[0]=b[0];
for(i=1;i<n;i++)
{
t[i]=t[i-1]+b[i];
}
printf("\tProcess \tTurnAround time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%f \n",i,t[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
avg+=t[i];
}
tavg=avg/n;
printf("Average turn around time %f:\n",tavg);
break;
case 4:
w[0]=0;
for(i=1;i<n;i++)
{
w[i]=t[i-1];
}
printf("\tProcess \t Waiting time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%f \n",i,w[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
avg1+=w[i];
}
wavg=avg1/n;
printf("Average waiting time%f:\n",wavg);
break;
case 5: int gd=DETECT,gm;
int x1,y1,x2,y2;
x1=y1=100;
y2=150;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setbkcolor(5);
outtextxy(250,250,"GANNT CHART");
for(i=0;i<n;i++)
{
rectangle(x1,y1,x1+b[i],y2);
x1=x1+b[i];
}
//x2=x2+b[i];
for(i=0;i<n;i++)
{
outtextxy(x1+5,y2+5,itoa(i,"t[i]",100));
outtextxy((x1+(x2-x1)/2),125,itoa(b[i],"p", 10));
}
break;
case 6 : exit(0);
break;
default : exit(0);
}
}while(ch!=0);
}

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#define SIZE 50
float w[SIZE],t[SIZE],tavg,wavg,avg=0.0,avg1=0.0;
int b[SIZE],b1[SIZE],i,n,ch,ch1;

void main()
{
clrscr();
printf("\n\t******Scheduling Algorithms******\t\n");
do
{
printf(" 1.Enter Input Values\n 2.Display Input Table\n 3.Turn around time\n 4.W
aiting Time\n 5.GANNT CHART\n 6.EXIT");
printf("Enter the choice:");
scanf("%d",&ch);
switch(ch)
{
case 1 : printf("Enter the number of processes:");
scanf("%d",&n);
printf("\nEnter the processes burst times\n");
for(i=0;i<n;i++)
{
printf("Enter the burst time of process%d:",i);
scanf("%d",&b1[i]);
}
for(i=0;i<n;i++)
{
b[i]=b1[i];
}
for(i=0;i<n;i++)
for(int j=0;j<n;j++)
if(b[i]<b[j])
{
int temp=b[i];
b[i]=b[j];
b[j]=temp;
}
break;
case 2: printf("The Input table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b1[i]);
}
printf("The sorted table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b[i]);
}
break;

case 3: t[0]=b[0];
for(i=1;i<n;i++)
{
t[i]=t[i-1]+b[i];
}
printf("\tProcess \tTurnAround time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%f \n",i,t[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
avg+=t[i];
}
tavg=avg/n;
printf("Average turn around time %f:\n",tavg);
break;
case 4:
w[0]=0;
for(i=1;i<n;i++)
{
w[i]=t[i-1];
}
printf("\tProcess \t Waiting time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%f \n",i,w[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
avg1+=w[i];
}
wavg=avg1/n;
printf("Average waiting time%f:\n",wavg);
break;
case 5: int gd=DETECT,gm;
int x1,y1,x2,y2;
x1=y1=100;
y2=150;
initgraph(&gd,&gm,"c:\\tc\\bgi");
setbkcolor(5);
outtextxy(250,250,"GANNT CHART");
for(i=0;i<n;i++)
{
rectangle(x1,y1,x1+b[i],y2);
x1=x1+b[i];
}
//x2=x2+b[i];
for(i=0;i<n;i++)
{
outtextxy(x1+5,y2+5,itoa(i,"t[i]",100));
outtextxy((x1+(x2-x1)/2),125,itoa(b[i],"p", 10));
}
break;
case 6 : exit(0);
break;
default : exit(0);
}
}while(ch!=0);
}
//
//RoundRobin..

#include<conio.h>
#include<stdio.h>
void main()
{
int n,i,q,next=-1,x,k=0;
float BT[20],TT[20],BTvar,sum=0.0,WT[20];
float awt=0,att=0;
printf("Enter the number of processes\n");
scanf("%d",&n);
printf("\n Enter burst time \n");
for(i=0;i<n;i++)
{scanf("%f",&BT[i]);
BTvar=BTvar+BT[i];
}
printf("\n Enter the quantum time of CPU\n");
scanf("%d",&q);
do
{ //1
next++;
if(next>n)
next=0;
if(BT[next]!=0)
{ //2
if(BT[next]<q)
{ //3
k=k+BT[next]; BT[next]=0;
} //3
else
{ //4
BT[next]=BT[next]-q;
k=k+q;
} //4
if(BT[next]==0)
{ //5
TT[next]=k;
sum+=TT[next];
} //5
}
}while(sum<BTvar); //1
printf("\n Turnaround time \n ");
for(i=0;i<n;i++)
{
printf(" P%d = %d \t TT%d = %f \n",i,i,i,TT[i]);
att+=TT[i];
}
WT[0]=0;
k=0;
printf("\n Waiting time \n");
for(i=1;i<n;i++)
{
if(TT[i-1]<q)
WT[i]=TT[i-1];
else
WT[i]=k+q;
k+=WT[i];
}
for(i=0;i<n;i++)
{
printf("P%d = %d \t WT%d= %f \n",i,i,i,WT[i]);
awt+=WT[i];
}
printf("\n Average Waiting time = %f : ",(awt/n));
printf("\n Aveage Turnaroundtime = %f : ",(att/n));
getch();
}
#include<stdio.h> #include<conio.h> int i,j,k,n,a[20],b[20],c[20],
u[10]; int m=0,temp,tt,t,tp; float var=0.0; void main()
{ printf("Enter the number of jobs\n"); scanf("%d",&n); printf
("\nEnter the order of jobs entering the queue\n"); for(i=0;i<n;i++)
scanf("%d",&a[i]); printf("Enter the burst time for each job\n"); f
or(i=0;i<n;i++) scanf("%d",&b[i]); printf("Enter the priority of eac
h job\n"); for(i=0;i<n;i++) scanf("%d",&c[i]); for(i=0;i<n;i++
) for(j=1;j<n;j++) for(k=0;k<n;k++) if(c[i]>c[j]) {
temp=c[i]; c[i]=c[j]; c[j]=c[i]; tp=a[i]; a[i]=a[j];
a[j]=tp; t=b[i]; b[i]=b[j]; b[j]=t; }printf("\n___
__________________________________________\n");for(i=n-1;i>=0;i--){ printf(" %d"
, a[i]); printf(" || ");}printf("\n___________________________________________
__\n");j=0;printf("%d",j);u[0]=0;for(k=n-1;k>=0;k--){ j+=b[k]; u[m]=j; m++; var+
=j; printf(" %d",j);}t=0;temp=0;k=0;printf("\n Waiting time \t turnaround time
\n");for(m=n-1;m>=0;m--){ t=u[m]; m--; tt=u[m]; m++; printf("\n job %d: \t %d \t
%d\n",a[k],tt,t); k++;}printf("\n Avg TAT = %f\n",(var/n));printf("Avg WT = %f\
n",(var-j)/n);getch();} //Try one more..#include<stdio.h>#include<conio.h>void
main(){int b1[10],b[10],i,n,j,temp; printf("Enter the num \n");
scanf("%d",&n); printf("Enter the burst time of process%d:",i
); for(i=0;i<n;i++)
scanf("%d",&b1[i]); for(i=0;i<n;i++)
{ b[i]=b1[i];
} for(i=0;i<n;i++)
for(j=0;j<n;j++) if(b[i]<b[j])
{ temp=b[i];
b[i]=b[j]; b[j]=temp;
} printf("The Input table\n");
printf("\tprocess \tburst time"); for(i=0;i<n;i++)
{ printf("\n \t%d \t\t%d \n",i,b1[i]);
} printf("The sorted table\n");
printf("\tprocess \tburst time"); for(i=0;i<n;i++)
{ printf("\n \t%d \t\t%d \n",i,b[i]);
} getch(); } #include<
stdio.h>
#include<conio.h>
int i,j,k,n,a[20],b[20],c[20],u[10];
int m=0,temp,tt,t,tp;
float var=0.0;
void main()
{
printf("Enter the number of jobs\n");
scanf("%d",&n);
printf("\nEnter the order of jobs entering the queue\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the burst time for each job\n");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
printf("Enter the priority of each job\n");
for(i=0;i<n;i++)
scanf("%d",&c[i]);
for(i=0;i<n;i++)
for(j=1;j<n;j++)
for(k=0;k<n;k++)
if(c[i]>c[j])
{
temp=c[i];
c[i]=c[j];
c[j]=c[i];
tp=a[i];
a[i]=a[j];
a[j]=tp;
t=b[i];
b[i]=b[j];
b[j]=t;
}
printf("\n_____________________________________________\n");
for(i=n-1;i>=0;i--)
{
printf(" %d", a[i]);
printf(" || ");
}
printf("\n_____________________________________________\n");
j=0;
printf("%d",j);
u[0]=0;
for(k=n-1;k>=0;k--)
{
j+=b[k];
u[m]=j;
m++;
var+=j;
printf(" %d",j);
}
t=0;
temp=0;
k=0;
printf("\n Waiting time \t turnaround time \n");
for(m=n-1;m>=0;m--)
{
t=u[m];
m--;
tt=u[m];
m++;
printf("\n job %d: \t %d \t %d\n",a[k],tt,t);
k++;
}
printf("\n Avg TAT = %f\n",(var/n));
printf("Avg WT = %f\n",(var-j)/n);
getch();
}

//Try one more..


#include<stdio.h>
#include<conio.h>
void main()
{int b1[10],b[10],i,n,j,temp;
printf("Enter the num \n");
scanf("%d",&n);
printf("Enter the burst time of process%d:",i);
for(i=0;i<n;i++)
scanf("%d",&b1[i]);
for(i=0;i<n;i++)
{
b[i]=b1[i];
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(b[i]<b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
}
printf("The Input table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b1[i]);
}
printf("The sorted table\n");
printf("\tprocess \tburst time");
for(i=0;i<n;i++)
{
printf("\n \t%d \t\t%d \n",i,b[i]);
}
getch();
}

Вам также может понравиться