OUTPUT:
enter no of processes: 5
enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1
p_name P_time w_time
eee 1 0
ccc 2 1
bbb 3 3
aaa 4 6
ddd 5 10
total waiting time=20
avg waiting time=4.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include<stdio.h> #include<conio.h> #include<process.h> void main() { char p[10][5],temp[5]; int tot=0,wt[10],pt[10],i,j,n,temp1; float avg=0; clrscr(); printf("enter no of processes:"); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter process%d name:\n",i+1); scanf("%s",&p[i]); printf("enter process time"); scanf("%d",&pt[i]); } for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(pt[i]>pt[j]) { temp1=pt[i]; pt[i]=pt[j]; pt[j]=temp1; strcpy(temp,p[i]); strcpy(p[i],p[j]); strcpy(p[j],temp); } } } wt[0]=0; for(i=1;i<n;i++) { wt[i]=wt[i-1]+et[i-1]; tot=tot+wt[i]; } avg=(float)tot/n; printf("p_name\t P_time\t w_time\n"); for(i=0;i<n;i++) printf("%s\t%d\t%d\n",p[i],et[i],wt[i]); printf("total waiting time=%d\n avg waiting time=%f",tot,avg); getch(); } |
OUTPUT:
enter no of processes: 5
enter process1 name: aaa
enter process time: 4
enter process2 name: bbb
enter process time: 3
enter process3 name: ccc
enter process time: 2
enter process4 name: ddd
enter process time: 5
enter process5 name: eee
enter process time: 1
p_name P_time w_time
eee 1 0
ccc 2 1
bbb 3 3
aaa 4 6
ddd 5 10
total waiting time=20
avg waiting time=4.00
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
September 30th, 2009 at 7:07 pm
it is not working , it is not showing and taking the ‘time value’ for different process .pls sort out the problem and send the code to my id
October 20th, 2009 at 3:21 pm
This program shows errors so plz correct it and send me.
November 10th, 2009 at 8:14 pm
plz write the code in c++ for preemtive scheduling
December 24th, 2009 at 2:41 am
hi for all
this is the code after correct it
so thanks man you are great (Sorry for bag English)
#include
#include
#include
void main()
{
char p[10][5],temp[5];
int tot=0,wt[10],pt[10],i,j,n,temp1;
float avg=0;
cout<>n;
cout<<endl;
for(i=0;i<n;i++)
{
cout<<"Enter Process Name "<>p[i];
//cout<<endl;
cout<<"Enter Barst Time time for Process "<<p[i]<>pt[i];
cout<<endl;
}
for(i=0;i<n-1;i++)
{
for(j=i+1;jpt[j])
{
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+pt[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],pt[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
}
December 24th, 2009 at 2:47 am
sorry
When you paste the code Here it will Appear incorrectly
January 3rd, 2010 at 1:03 pm
#include
#include
#include
void main()
{
char p[10][5];
int tot=0,wt[10],i,n;
float avg=0;
clrscr();
printf(“enter no of processes:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
January 16th, 2010 at 12:14 pm
make sure uf da declarations….u msd to declare et array…..
February 4th, 2010 at 12:52 pm
Glad to see that this site works well on my Droid , everything I want to do is functional. Thanks for keeping it up to date with the latest.
February 18th, 2010 at 9:38 am
#include
#include
#include
void main()
{
char p[10][5],temp[5];
int tot=0,wt[10],pt[10],i,j,n,temp1;
float avg=0;
clrscr();
printf(“enter no of processes:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;jpt[j])
{
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
March 11th, 2010 at 11:41 pm
all these prog has been made by avoiding arrival time.please take that into consideration
March 14th, 2010 at 10:25 am
HI THIS IS JAGADHEESWAR.VERY VERY THANKS FOR PUBLISHING THE C PROGRAMS IN THIS WEBSITE. I HAVE JAVA LAB PROGRAMS FOR JNTU BTECH STUDENTS WHICH HAS BEEN EXECUTED. (34 PROGRAMS). IF YOU WANT THAT I WILL SEND IT AS A MAIL TO YOU. VERY THANKS FOR PUBLISHING OS SCHEDULING ALGORITHMS . THANKYOU.
March 14th, 2010 at 10:32 am
Sir, how can i create a mini project for jntu.please send the details.
May 19th, 2010 at 3:12 pm
could you please send those programs to me. because i need some
references on my os class..specially the shortest job first program.
thanks alot. any program will be highly appreciated.
May 19th, 2010 at 3:14 pm
by the way i’m using a cygwin compiler. thanks
June 1st, 2010 at 6:09 pm
// A program of sjf algorithm with no preemption
#include
#include
main()
{
int p[10],wt[10],bt[10],tat[10],i,j,twt=0,ttat=0,temp,n;
float awt,atat;
clrscr();
printf(“enter the no. of process=>\n”);
scanf(“%d”,&n);
printf(“enter process=>\n”);
for(i=0;i”);
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
for(i=0;i<n;i++)
{
for(j=0;jbt[j+1])
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
temp=bt[j];
bt[j]=bt[j+1];
bt[j+1]=temp;
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1]; //waiting time
twt=twt+wt[i]; //total waiting time
}
for(i=0;i<n;i++)
{
tat[i]=wt[i]+bt[i]; //turn around time
ttat=ttat+tat[i]; // total turned around time
}
awt=(float)twt/n; //avg waiting time
atat=(float)ttat/n; //avg turn around time
printf("p_number\t P_bt\t p_wt \t p_tat \n");
for(i=0;i<n;i++)
printf("%d\t\t%d\t%d\t%d\n",p[i],bt[i],wt[i],tat[i]);
printf("total waiting time=%d\n avg waiting time=%f",twt,awt);
printf("\ntotal turnedaroundtime=%d\n avg turnedaround time=%f",ttat,atat);
getch();
}
July 27th, 2010 at 12:49 pm
sir ur program is not print the avg time and turn around time properly
August 24th, 2010 at 2:16 pm
I need the c++ programs for scheduling algorithms. can anyone provide those?
September 29th, 2010 at 10:34 am
hi sir,
i thanks a lot for helping us in the
os programs.
thanks and regard,
brajkishor
noida ncr
September 29th, 2010 at 10:40 am
thanks for ur help
September 29th, 2010 at 10:44 am
This is compiled program which is error free….
#include
#include
#include
void main()
{
char p[10][5];
int tot=0,wt[10],pt[10],i,n;
float avg=0;
clrscr();
printf(“enter no of processes:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+pt[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],pt[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
September 29th, 2010 at 10:47 am
1st include have stdio.h
2nd include have conio.h
3rd include have process.h
November 27th, 2010 at 12:49 pm
I want c code for Disk Scheduling algorithms such as SCAN CSCAN LOOK
December 1st, 2010 at 10:51 pm
#include
#include
#include
void main()
{
char p[20][10];
int tot=0,wt[10],i,n,pt[25];
float avg=0;
clrscr();
printf(“enter no of processes:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+pt[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],pt[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
January 18th, 2011 at 10:17 am
@jagadeeswar.dude pl. send me ur 34 java programs to my mail id
santhosh.ak47@gmail.com
January 18th, 2011 at 10:45 pm
plz help me in making programs using simple multilevel cpu scheduling
and feedback multilevel cpu scheduling algorithms in c++ or c.
i searched all net 4 this bt did not find any thing.
January 19th, 2011 at 4:28 pm
#include
#include
#include
void main()
{
char p[10][5],temp[5];
int tot=0,wt[10],pt[10],i,j,n,temp1;
float avg=0;
clrscr();
printf(“enter no of processes:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;jpt[j])
{
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+et[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],et[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
February 3rd, 2011 at 8:37 pm
if any one having os material for 8 units?????
February 16th, 2011 at 12:34 am
can nybody mail me all the cpu schedulling programs to neo1412@gmail.com
i need java prograams as well as os lab programs i ll be thankfull if nybody could mail me ASAp
May 28th, 2011 at 2:37 pm
thanks for this code
June 29th, 2011 at 8:06 pm
hai iam sravani please send me a step wise SJF algorithm
July 10th, 2011 at 1:11 pm
hi,i need the java as well as os lab programs as soon as possible.i will be thankful if u send it to my id ntalath@ gmail.com
July 20th, 2011 at 5:43 pm
can you send the 34 program scheduling code.i need it in complete data and format…plz i need it in my report…..thanks a lot….trexylove_2000@yahoo.com
August 12th, 2011 at 12:38 pm
check et is not declared in main….and place the pt instead of et in above program
August 12th, 2011 at 12:39 pm
place the pt[] instead of et[]
August 12th, 2011 at 12:42 pm
delete ‘et’ and put ‘pt’ in place of ‘et’ so u will get correct answer for above program
August 15th, 2011 at 6:15 pm
do you have a any program
in FCFS,SJF,priority and Round robin if anyone know’s please inform me
August 25th, 2011 at 9:51 pm
all these prog has been made by avoiding arrival time.please take that into consideration
September 1st, 2011 at 3:05 pm
arrival time has not be taken into cosideration
September 3rd, 2011 at 8:00 pm
thanks for this program & i need some other os program also plz anyone send to my id.
September 13th, 2011 at 9:43 am
it showing a problem that”strcpy function should be a prototype”……give me some solution .. thanks
September 17th, 2011 at 5:20 pm
do you have a any program
in priority and Round robin. including the arrival time pls..
i need it ASAP.email me.tnx. christiangilaquino@yahoo.com
September 18th, 2011 at 2:59 pm
it showing a problem that”strcpy function should have a prototype”……give me some solution please help…………
September 22nd, 2011 at 9:11 pm
line no 37:wt[i]=wt[i-1]+et[i-1];
it should be wt[i]=wt[i-1]+pt[i];for the required output
September 22nd, 2011 at 9:16 pm
following is the correct code use this one:
#include
#include
#include
#include
void main()
{
char p[10][5],temp[5];
int tot=0,wt[10],pt[10],i,j,n,temp1,et[100];
float avg=0;
clrscr();
printf(“enter no of processes:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;jpt[j])
{
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+pt[i];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],pt[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
September 23rd, 2011 at 8:43 pm
Please can any 1 tell how can we write c code for SJF(Non-Pre-emptive)
If we take input as arrival time and service time from user and perform SJF as per arrival of processes and procees among them with shortest service time
Please asap…..
September 30th, 2011 at 12:46 am
thnx there, i really need this.,
i also want disk scheduling algorithm (elevator algorithm).,
so plz any1 can post it 4 me…
September 30th, 2011 at 9:29 pm
C program for SJF CPU Scheduling Algorithm:
#include
#include
#include
#include
void main()
{
char p[10][5],temp[5];
int tot=0,wt[10],pt[10],i,j,n,temp1;
float avg=0;
clrscr();
printf(“enter no of processes:”);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("enter process%d name:\n",i+1);
scanf("%s",&p[i]);
printf("enter process time");
scanf("%d",&pt[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;jpt[j])
{
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
strcpy(temp,p[i]);
strcpy(p[i],p[j]);
strcpy(p[j],temp);
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+pt[i-1];
tot=tot+wt[i];
}
avg=(float)tot/n;
printf("p_name\t P_time\t w_time\n");
for(i=0;i<n;i++)
printf("%s\t%d\t%d\n",p[i],pt[i],wt[i]);
printf("total waiting time=%d\n avg waiting time=%f",tot,avg);
getch();
}
September 30th, 2011 at 9:30 pm
# include
# include
# include
# include
September 30th, 2011 at 9:31 pm
#include stdio.h
#include conio.h
#include process.h
#include string.h
October 31st, 2011 at 2:02 pm
hey! i want all sheduling programs in preemptive nd non preemptive ……………
so plzzzzz any one can send for me. pls
November 5th, 2011 at 12:06 pm
Hello sir,
I have seen the code but I dont have a clue how I can run or where do I save it?please tell me how to save and run this program..
November 8th, 2011 at 11:13 pm
can any one tell me plz wht is tis jpt[j] in the above program.i will b highly grateful!!!!!!!!!!!!!!!
November 17th, 2011 at 3:56 pm
thanks for u
for giving
this type of programms
bt this are static arrival times of proceeossrs
if some processor comes dynamically with some arrival time
?????
December 4th, 2011 at 5:23 pm
Can any1 help me wid c code for multilevel round roubin scheduling pls???
December 12th, 2011 at 6:10 pm
Fucking syntax errors . don’t know how to fix it .
December 31st, 2011 at 10:19 am
i want all cpu scheduling algorithms with programmes
tell me any site
but remeber one thing i want small programmes