C program for Shortest Job Next
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int s,t[20],temp,n,x[20],w[20],i,j,c,d,b[20];
float avgw,avgt;
clrscr();
printf("\n Enter no.of job:");
scanf("%d",&n);
printf("enter the job:");
for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
x[i]=i;
}
for(i=1;i<=n-1;i++)
{
for(j=i+1;j<=n;j++)
{
if(b[i]>b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
s=x[i];
x[i]=x[j];
x[j]=s;
}
}
}
c=0;
d=0;
for(i=1;i<=n;i++)
{
w[i]=w[i-1]+b[i-1];
t[i]=b[i]+t[i-1];
w[1]=0;
t[1]=b[1];
c+=w[i];
d+=t[i];
}
avgw=(float)c/n;
avgt=(float)d/n;
printf("job \t waiting time \t service time \t turn around time \t \n :");
for(i=1;i<=n;i++)
{
printf("%d \t %d \t ",x[i],b[i]);
printf("%d \t %d \t",w[i],t[i]);
printf("\n");
}
printf("average wait time %f \n",avgw);
printf("average turn around %f \n",avgt);
getch();
} |
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int s,t[20],temp,n,x[20],w[20],i,j,c,d,b[20];
float avgw,avgt;
clrscr();
printf("\n Enter no.of job:");
scanf("%d",&n);
printf("enter the job:");
for(i=1;i<=n;i++)
{
scanf("%d",&b[i]);
x[i]=i;
}
for(i=1;i<=n-1;i++)
{
for(j=i+1;j<=n;j++)
{
if(b[i]>b[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
s=x[i];
x[i]=x[j];
x[j]=s;
}
}
}
c=0;
d=0;
for(i=1;i<=n;i++)
{
w[i]=w[i-1]+b[i-1];
t[i]=b[i]+t[i-1];
w[1]=0;
t[1]=b[1];
c+=w[i];
d+=t[i];
}
avgw=(float)c/n;
avgt=(float)d/n;
printf("job \t waiting time \t service time \t turn around time \t \n :");
for(i=1;i<=n;i++)
{
printf("%d \t %d \t ",x[i],b[i]);
printf("%d \t %d \t",w[i],t[i]);
printf("\n");
}
printf("average wait time %f \n",avgw);
printf("average turn around %f \n",avgt);
getch();
}
Editorial Team
We are a group of young techies trying to provide the best study material for all Electronic and Computer science students. We are publishing Microcontroller projects, Basic Electronics, Digital Electronics, Computer projects and also c/c++, java programs.
yes i too sjf need using structures