In this program there is error in processing time of last process..plz check the error...
the program is as - #include<stdio.h>
-
#include<conio.h>
-
void main()
-
{
-
float avgwt,avgtt;
-
char pname[10][10],c[10][10];
-
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
-
clrscr();
-
printf("\n\n Enter the number of processes:");
-
scanf("%d",&n);
-
printf("\n\n Enter the NAME,BURSTTIME and ARRIVALTIME of the processes");
-
for(i=1;i<=n;i++)
-
{
-
printf("\n\n NAME :");
-
scanf("%s",&pname[i]);
-
printf("\n\nBURST TIME :");
-
scanf("%d",&bt[i]);
-
printf("\n\n ARRIVAL TIME :");
-
scanf("%d",&at[i]);
-
}
-
for(i=1;i<n;i++)
-
for(j=i+1;j<n;j++)
-
{
-
if(at[i]==at[j])
-
if(bt[i]>bt[j])
-
{
-
t=at[i];
-
at[i]=at[j];
-
at[j]=t;
-
q=bt[i];
-
bt[i]=bt[j];
-
bt[j]=q;
-
strcpy(c[i],pname[i]);
-
strcpy(pname[i],pname[j]);
-
strcpy(pname[j],c[i]);
-
}
-
if(at[i]!=at[j])
-
if(bt[i]>bt[j])
-
{
-
t=at[i];
-
at[i]=at[j];
-
at[j]=t;
-
q=bt[i];
-
bt[i]=bt[j];
-
bt[j]=q;
-
strcpy(c[i],pname[i]);
-
strcpy(pname[i],pname[j]);
-
strcpy(pname[j],c[i]);
-
}
-
}
-
wt[1]=0;
-
for(i=1;i<=n-1;i++)
-
{
-
wt[i+1]=wt[i]+bt[i];
-
sum=sum+(wt[i]-at[i]);
-
sbt=sbt+(wt[i+1]-at[i]);
-
tt[i]=wt[i]+bt[i];
-
ss=ss+bt[i];
-
}
-
printf("\n\n GANTT CHART");
-
printf("\n\n ------------------------------------------------------------------\n");
-
for(i=1;i<=n;i++)
-
{
-
printf("|\t%s\t",pname[i]);
-
sbt=sbt+wt[i+1];
-
tt[i]=wt[i]+bt[i];
-
ss=ss+bt[i];
-
}
-
printf("\n\nGANTT CHART");
-
printf("\n--------------------------------------------------------------------\n");
-
for(i=1;i<=n;i++)
-
{
-
printf("|\t%s\t",pname[i]);
-
}
-
printf("\n--------------------------------------------------------------------\n");
-
for(i=1;i<=n;i++)
-
{
-
printf("%d\t\t",wt[i]);
-
}
-
printf("%d\n",ss);
-
printf("\n--------------------------------------------------------------------\n");
-
printf("\n\n Total WAITING TIME of the process=%d",sum);
-
printf("\n\nTotal TURNAROUND TIME of the process=%d",sbt);
-
avgwt=(float)sum/n;
-
avgtt=(float)sbt/n;
-
printf("\n\nAverage WAITING TIME of the process=%f",avgwt);
-
printf("\n\nAverage TURNAROUND TIME of the process=%f",avgtt);
-
getch();
-
}
-
10 3846
I checked the code.
Its compiling as well as running properly, without any error.
What error are you taking about?
Is it logical error or what?
yes,there is logical error in this.....
check line number 21
Don't you think it has to be:
Otherwise it will skip the last record.
i change it.but the error remain same.... -
Enter the NAME,BURSTTIME and ARRIVALTIME of the processes
-
-
NAME :a
-
-
-
BURST TIME :3
-
-
-
ARRIVAL TIME :1
-
-
-
NAME :b
-
-
-
BURST TIME :2
-
-
-
ARRIVAL TIME :1
-
-
-
NAME :c
-
-
-
BURST TIME :5
-
-
-
ARRIVAL TIME :1
-
-
-
GANTT CHART
-
-
------------------------------------------------------------------
-
| b | a | c
-
-
GANTT CHART
-
--------------------------------------------------------------------
-
| b | a | c
-
--------------------------------------------------------------------
-
0 2 5 15
-
-
--------------------------------------------------------------------
-
-
-
Total WAITING TIME of the process=0
-
-
Total TURNAROUND TIME of the process=12
-
-
Average WAITING TIME of the process=0.000000
-
-
Average TURNAROUND TIME of the process=4.000000
-
this is the output of one example which has same arrival time....in this output see in grant chart the process completion time of process c should be 10 but it shows 15..
-
# GANTT CHART
-
# --------------------------------------------------------------------
-
# | b | a | c
-
# --------------------------------------------------------------------
-
# 0 2 5 15
-
#
-
# --------------------------------------------------------------------
-
According to your code, these figures are waiting times.
0,2,5 are the waiting times for respective processes. Like you are saying, you need 10 after 5, which makes no sense. Because, there is no fourth process in queue to display its waiting time.
15 is getting printed because of line 80. You are printing 'ss' variable.
You can just comment that line, and everything will start making sense.
If you want some other thing to be printed, like burst time or anything else, tell me.
thanku for this....it shows waiting time zero which is incorect and trunaround time is also incorrect.
Trunaround time=time terminated-time entered
TAT of process a=5-1=4
TAt of process b=2-1=1
TAT of process c=10-1=9
then tatal trunaround time should be4+1+9=14
and avrage TAT should be 14/4
bt it show 12
plz check that waiting time and trunaround time..
Sure Sir/Mam,
Give me few minutes.
the problem of trunaround time has solved now there was mistake in the for loop....
wt[1]=0;
for(i=1;i<=n-1;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=sum+(wt[i]-at[i]);
sbt=sbt+(wt[i+1]-at[i]);
tt[i]=wt[i]+bt[i];
ss=ss+bt[i];
in this loop the i is start from 1 thats way it skip the first process time... - wt[1]=0;
-
for(i=1;i<=n-1;i++)
-
{
-
j=i-1;
-
wt[i+1]=wt[i]+bt[i];
-
sum=sum+(wt[i]-at[j]);
-
sbt=sbt+(wt[i+1]-at[j]);
-
tt[i]=wt[i]+bt[i];
-
ss=ss+bt[i];
-
}
plz check it now plz plz
and plz solve the error of waiting time.
-
#include<stdio.h>
-
#include<conio.h>
-
void main()
-
{
-
float avgwt,avgtt;
-
char pname[10][10],c[10][10];
-
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
-
clrscr();
-
printf("\n\n Enter the number of processes:");
-
scanf("%d",&n);
-
printf("\n\n Enter the NAME,BURSTTIME and ARRIVALTIME of the processes");
-
for(i=1;i<=n;i++)
-
{
-
printf("\n\n NAME :");
-
scanf("%s",&pname[i]);
-
printf("\n\nBURST TIME :");
-
scanf("%d",&bt[i]);
-
printf("\n\n ARRIVAL TIME :");
-
scanf("%d",&at[i]);
-
}
-
for(i=1;i<=n;i++)
-
for(j=i+1;j<n;j++)
-
{
-
if(at[i]==at[j])
-
if(bt[i]>bt[j])
-
{
-
t=at[i];
-
at[i]=at[j];
-
at[j]=t;
-
q=bt[i];
-
bt[i]=bt[j];
-
bt[j]=q;
-
strcpy(c[i],pname[i]);
-
strcpy(pname[i],pname[j]);
-
strcpy(pname[j],c[i]);
-
}
-
if(at[i]!=at[j])
-
if(bt[i]>bt[j])
-
{
-
t=at[i];
-
at[i]=at[j];
-
at[j]=t;
-
q=bt[i];
-
bt[i]=bt[j];
-
bt[j]=q;
-
strcpy(c[i],pname[i]);
-
strcpy(pname[i],pname[j]);
-
strcpy(pname[j],c[i]);
-
}
-
}
-
wt[1]=0;
-
for(i=1;i<=n-1;i++)
-
{
-
wt[i+1]=wt[i]+bt[i];
-
sum=sum+(wt[i]-at[i]);
-
sbt=sbt+(wt[i+1]-at[i]);
-
tt[i]=wt[i]+bt[i];
-
ss=ss+bt[i];
-
}
-
sum = 0;
-
sbt = 0;
-
for(i=1;i<=n;i++)
-
{
-
sum=sum + wt[i];
-
sbt = sbt + (wt[i] + bt[i] - at[i]);
-
}
-
-
printf("\n\n GANTT CHART");
-
printf("\n\n ------------------------------------------------------------------\n");
-
for(i=1;i<=n;i++)
-
{
-
printf("|\t%s\t",pname[i]);
-
//sbt=sbt+wt[i+1];
-
tt[i]=wt[i]+bt[i];
-
ss=ss+bt[i];
-
}
-
printf("\n\nGANTT CHART");
-
printf("\n--------------------------------------------------------------------\n");
-
for(i=1;i<=n;i++)
-
{
-
printf("|\t%s\t",pname[i]);
-
}
-
printf("\n--------------------------------------------------------------------\n");
-
for(i=1;i<=n;i++)
-
{
-
printf("%d\t\t",wt[i]);
-
}
-
printf("%d\n",ss);
-
printf("\n--------------------------------------------------------------------\n");
-
printf("\n\n Total WAITING TIME of the process=%d",sum);
-
printf("\n\nTotal TURNAROUND TIME of the process=%d",sbt);
-
avgwt=(float)sum/n;
-
avgtt=(float)sbt/n;
-
printf("\n\nAverage WAITING TIME of the process=%f",avgwt);
-
printf("\n\nAverage TURNAROUND TIME of the process=%f",avgtt);
-
getch();
-
}
-
Added code from 60 to 66.
Commented line 73.
Let me know if that helps you.
thanku thanku so much......yes it is working correctly...
really thanku so much..
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Warren |
last post by:
Is there a way to check if the system is currently in Daylight Saving Time?
I'm trying to convert a DateTime from GMT to CST or CDT, but I'd like to be
able to figure out which at runtime. Thanks.
|
by: Lodewijk Smit |
last post by:
Hi,
In the C standard of 1999 additional mathematical functions are added.
For example, beside the traditional
double sin(double x);
there are also the functions:
float sinf(float x);...
|
by: catherene |
last post by:
hai,
in IEEE software jan/feb 2003 an article was published
regarding suitability of C# and .NET in real-time systems.
can anybody is doing research on its analysis of
schedulability.
kindly...
|
by: kaka |
last post by:
I'm runnig Redhat 7.3 with postgresql 7.3.4 builded from sources and
upgraded recently. I receive this error ( never received before upgrade
) and I don' t know what to do.
Error while executing...
|
by: John Smith |
last post by:
Hi
I'm porting some C++ code to new platforms and have some 1-byte aligned
structures which need a specific size. Since datatypes can vary on different
platforms (which I found out the hard way...
|
by: Notgiven |
last post by:
You want to check scheduling conflicts and you have a record like:
appointments(table):
apptID
beginningDate
endingDate
beginningTime
endingTime
It's easy enough to check if a time is...
|
by: nex85 |
last post by:
hi!
HOUR FROM TIME
i) does anyone know how to determine which hour a time value lies in? the arrival time is in hh:mm:ss format. for e.g.: for an arrival time of 17:00:26, the correct conversion...
|
by: paragborkar |
last post by:
Hello friends,
I am newbie in C. I have one enum variable for events. There are 2
types of events and I want to split them, but one can add events enums
later for the both the types.I am keeping...
|
by: greg chu |
last post by:
Hi, not sure who has done this.
I want to set up a time interval that could be pass midnight. so
people can enter
8AM to 8AM (pass midnight to 2nd day)
8AM to 2 AM (pass midnight to 2nd day)...
|
by: wizard |
last post by:
Hello Friends,
There is a PHP function checkdate to check if a date is a valid
Gregorian date.
Is there any such function to check for a valid time like something in
hh:mm:ss format? If not, can...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |