473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Check error in Arrival time of SJF scheduling

In this program there is error in processing time of last process..plz check the error...
the program is as
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. float avgwt,avgtt;
  6. char pname[10][10],c[10][10];
  7. int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
  8. clrscr();
  9. printf("\n\n Enter the number of processes:");
  10. scanf("%d",&n);
  11. printf("\n\n Enter the NAME,BURSTTIME and ARRIVALTIME of the processes");
  12. for(i=1;i<=n;i++)
  13. {
  14. printf("\n\n NAME :");
  15. scanf("%s",&pname[i]);
  16. printf("\n\nBURST TIME :");
  17. scanf("%d",&bt[i]);
  18. printf("\n\n ARRIVAL TIME :");
  19. scanf("%d",&at[i]);
  20. }
  21. for(i=1;i<n;i++)
  22. for(j=i+1;j<n;j++)
  23. {
  24. if(at[i]==at[j])
  25. if(bt[i]>bt[j])
  26. {
  27. t=at[i];
  28. at[i]=at[j];
  29. at[j]=t;
  30. q=bt[i];
  31. bt[i]=bt[j];
  32. bt[j]=q;
  33. strcpy(c[i],pname[i]);
  34. strcpy(pname[i],pname[j]);
  35. strcpy(pname[j],c[i]);
  36. }
  37. if(at[i]!=at[j])
  38. if(bt[i]>bt[j])
  39. {
  40. t=at[i];
  41. at[i]=at[j];
  42. at[j]=t;
  43. q=bt[i];
  44. bt[i]=bt[j];
  45. bt[j]=q;
  46. strcpy(c[i],pname[i]);
  47. strcpy(pname[i],pname[j]);
  48. strcpy(pname[j],c[i]);
  49. }
  50. }
  51. wt[1]=0;
  52. for(i=1;i<=n-1;i++)
  53. {
  54. wt[i+1]=wt[i]+bt[i];
  55. sum=sum+(wt[i]-at[i]);
  56. sbt=sbt+(wt[i+1]-at[i]);
  57. tt[i]=wt[i]+bt[i];
  58. ss=ss+bt[i];
  59. }
  60. printf("\n\n GANTT CHART");
  61. printf("\n\n ------------------------------------------------------------------\n");
  62. for(i=1;i<=n;i++)
  63. {
  64. printf("|\t%s\t",pname[i]);
  65. sbt=sbt+wt[i+1];
  66. tt[i]=wt[i]+bt[i];
  67. ss=ss+bt[i];
  68. }
  69. printf("\n\nGANTT CHART");
  70. printf("\n--------------------------------------------------------------------\n");
  71. for(i=1;i<=n;i++)
  72. {
  73. printf("|\t%s\t",pname[i]);
  74. }
  75. printf("\n--------------------------------------------------------------------\n");
  76. for(i=1;i<=n;i++)
  77. {
  78. printf("%d\t\t",wt[i]);
  79. }
  80. printf("%d\n",ss);
  81. printf("\n--------------------------------------------------------------------\n");
  82. printf("\n\n Total WAITING TIME of the process=%d",sum);
  83. printf("\n\nTotal TURNAROUND TIME of the process=%d",sbt);
  84. avgwt=(float)sum/n;
  85. avgtt=(float)sbt/n;
  86. printf("\n\nAverage WAITING TIME of the process=%f",avgwt);
  87. printf("\n\nAverage TURNAROUND TIME of the process=%f",avgtt);
  88. getch();
  89. }
  90.  
Oct 7 '10 #1
10 3846
ashitpro
542 Expert 512MB
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?
Oct 7 '10 #2
yes,there is logical error in this.....
Oct 7 '10 #3
ashitpro
542 Expert 512MB
check line number 21

Expand|Select|Wrap|Line Numbers
  1. for(i=1;i<n;i++)
Don't you think it has to be:

Expand|Select|Wrap|Line Numbers
  1. for(i=1;i<=n;i++)
Otherwise it will skip the last record.
Oct 7 '10 #4
i change it.but the error remain same....
Expand|Select|Wrap|Line Numbers
  1.  Enter the NAME,BURSTTIME and ARRIVALTIME of the processes
  2.  
  3.  NAME :a
  4.  
  5.  
  6. BURST TIME :3
  7.  
  8.  
  9.  ARRIVAL TIME :1
  10.  
  11.  
  12.  NAME :b
  13.  
  14.  
  15. BURST TIME :2
  16.  
  17.  
  18.  ARRIVAL TIME :1
  19.  
  20.  
  21.  NAME :c
  22.  
  23.  
  24. BURST TIME :5
  25.  
  26.  
  27.  ARRIVAL TIME :1
  28.  
  29.  
  30.  GANTT CHART
  31.  
  32.  ------------------------------------------------------------------
  33. |       b       |       a       |       c
  34.  
  35. GANTT CHART
  36. --------------------------------------------------------------------
  37. |       b       |       a       |       c
  38. --------------------------------------------------------------------
  39. 0               2               5               15
  40.  
  41. --------------------------------------------------------------------
  42.  
  43.  
  44.  Total WAITING TIME of the process=0
  45.  
  46. Total TURNAROUND TIME of the process=12
  47.  
  48. Average WAITING TIME of the process=0.000000
  49.  
  50. Average TURNAROUND TIME of the process=4.000000
  51.  
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..
Oct 7 '10 #5
ashitpro
542 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. # GANTT CHART
  2. # --------------------------------------------------------------------
  3. # |       b       |       a       |       c
  4. # --------------------------------------------------------------------
  5. # 0               2               5               15
  6. #  
  7. # --------------------------------------------------------------------
  8.  
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.
Oct 7 '10 #6
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..
Oct 7 '10 #7
ashitpro
542 Expert 512MB
Sure Sir/Mam,

Give me few minutes.
Oct 7 '10 #8
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...
Expand|Select|Wrap|Line Numbers
  1. wt[1]=0; 
  2. for(i=1;i<=n-1;i++)
  3. {
  4. j=i-1;
  5. wt[i+1]=wt[i]+bt[i];
  6. sum=sum+(wt[i]-at[j]);
  7. sbt=sbt+(wt[i+1]-at[j]);
  8. tt[i]=wt[i]+bt[i]; 
  9. ss=ss+bt[i]; 
plz check it now plz plz
and plz solve the error of waiting time.
Oct 7 '10 #9
ashitpro
542 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. float avgwt,avgtt;
  6. char pname[10][10],c[10][10];
  7. int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
  8. clrscr();
  9. printf("\n\n Enter the number of processes:");
  10. scanf("%d",&n);
  11. printf("\n\n Enter the NAME,BURSTTIME and ARRIVALTIME of the processes");
  12. for(i=1;i<=n;i++)
  13. {
  14. printf("\n\n NAME :");
  15. scanf("%s",&pname[i]);
  16. printf("\n\nBURST TIME :");
  17. scanf("%d",&bt[i]);
  18. printf("\n\n ARRIVAL TIME :");
  19. scanf("%d",&at[i]);
  20. }
  21. for(i=1;i<=n;i++)
  22. for(j=i+1;j<n;j++)
  23. {
  24. if(at[i]==at[j])
  25. if(bt[i]>bt[j])
  26. {
  27. t=at[i];
  28. at[i]=at[j];
  29. at[j]=t;
  30. q=bt[i];
  31. bt[i]=bt[j];
  32. bt[j]=q;
  33. strcpy(c[i],pname[i]);
  34. strcpy(pname[i],pname[j]);
  35. strcpy(pname[j],c[i]);
  36. }
  37. if(at[i]!=at[j])
  38. if(bt[i]>bt[j])
  39. {
  40. t=at[i];
  41. at[i]=at[j];
  42. at[j]=t;
  43. q=bt[i];
  44. bt[i]=bt[j];
  45. bt[j]=q;
  46. strcpy(c[i],pname[i]);
  47. strcpy(pname[i],pname[j]);
  48. strcpy(pname[j],c[i]);
  49. }
  50. }
  51. wt[1]=0;
  52. for(i=1;i<=n-1;i++)
  53. {
  54. wt[i+1]=wt[i]+bt[i];
  55. sum=sum+(wt[i]-at[i]);
  56. sbt=sbt+(wt[i+1]-at[i]);
  57. tt[i]=wt[i]+bt[i];
  58. ss=ss+bt[i];
  59. }
  60. sum = 0;
  61. sbt = 0;
  62. for(i=1;i<=n;i++)
  63. {
  64.   sum=sum + wt[i];
  65.   sbt = sbt + (wt[i] + bt[i] - at[i]);
  66. }
  67.  
  68. printf("\n\n GANTT CHART");
  69. printf("\n\n ------------------------------------------------------------------\n");
  70. for(i=1;i<=n;i++)
  71. {
  72. printf("|\t%s\t",pname[i]);
  73. //sbt=sbt+wt[i+1];
  74. tt[i]=wt[i]+bt[i];
  75. ss=ss+bt[i];
  76. }
  77. printf("\n\nGANTT CHART");
  78. printf("\n--------------------------------------------------------------------\n");
  79. for(i=1;i<=n;i++)
  80. {
  81. printf("|\t%s\t",pname[i]);
  82. }
  83. printf("\n--------------------------------------------------------------------\n");
  84. for(i=1;i<=n;i++)
  85. {
  86. printf("%d\t\t",wt[i]);
  87. }
  88. printf("%d\n",ss);
  89. printf("\n--------------------------------------------------------------------\n");
  90. printf("\n\n Total WAITING TIME of the process=%d",sum);
  91. printf("\n\nTotal TURNAROUND TIME of the process=%d",sbt);
  92. avgwt=(float)sum/n;
  93. avgtt=(float)sbt/n;
  94. printf("\n\nAverage WAITING TIME of the process=%f",avgwt);
  95. printf("\n\nAverage TURNAROUND TIME of the process=%f",avgtt);
  96. getch();
  97. }
  98.  
Added code from 60 to 66.
Commented line 73.

Let me know if that helps you.
Oct 7 '10 #10
thanku thanku so much......yes it is working correctly...
really thanku so much..
Oct 7 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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.
4
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);...
1
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...
2
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...
4
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...
5
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...
2
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...
5
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...
1
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)...
2
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
jinu1996
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.