#include<stdio.h>
main()
{
float avgwt,avgtt;
char pname[10][10],c[10][10];
int wt[10],tt[10],bt[10],at[1],t,q,i,n=10,sum=0,sbt=0,ttime,j,ss=0;
int randomp=rand() % 5+5;
int randomb=rand() % 1+9;
{
printf("\t\n Process Name :");
for(i=0;i<n;i++)
{
printf("%s",&pname[i][randomp] );
printf("%s",&bt[randomb] );
}
for(i=0;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[0]=0;
for(i=0;i<n;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=0;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=0;i<n;i++)
{
printf("|\t%s\t",pname[i]);
}
printf("\n--------------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("%d\t\t",wt[i]);
}
clrscr();
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);
}
}
SJF algorithym
Page 1 of 17 Replies - 2157 Views - Last Post: 20 January 2009 - 09:23 AM
#1
SJF algorithym
Posted 17 January 2009 - 11:31 PM
can u help me whats wrong with this code?...there's no error with the code but when i run it its said that abnormal program termination,null poinetr assigment..can u help me plss asap cause i badly need it...thanks in advance,,
Replies To: SJF algorithym
#2
Re: SJF algorithym
Posted 18 January 2009 - 03:40 AM
Someone please move this to C/C++ but:
you need to:
#include<stdlib.h>
#include<string.h>
#include<cstdlib>
and do a system("clear") instead of the clrscr().
And next time:
Don't forget to use [ code] [/ code] tags
you need to:
#include<stdlib.h>
#include<string.h>
#include<cstdlib>
and do a system("clear") instead of the clrscr().
And next time:
Don't forget to use [ code] [/ code] tags
#3
Re: SJF algorithym
Posted 18 January 2009 - 03:56 AM
1) Please 
2) This forum is for questions related to DIC.
3) Moved to C/C++
2) This forum is for questions related to DIC.
3) Moved to C/C++
#4
Re: SJF algorithym
Posted 20 January 2009 - 08:11 AM
I already did what you said but still its abnormal program termination and null pointer assigment...can you help me out of this code pls....i really need it...thanks in advance..
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
main()
{
float avgwt,avgtt;
char Process[10][10];
int wt[10],tt[10],bt[10],at[1],t,q,i,n=11,sum=0,sbt=0,ttime,j,ss=0;
int randomb=rand() % 1+9;
{
printf("\t\n Processes:");
for(i=0;i<n;i++)
{
printf("%s",&Process[i],&bt[randomb]);
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(bt[i]>bt[j])
{
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
}
}
printf("\n\nGANTT CHART");
printf("\n--------------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("|\t%s\t",Process[i]);
}
printf("\n--------------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("%d\t\t",wt[i]);
}
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=bt[i]-wt[i];
sbt=bt[i+1]-wt[i];
tt[i]=wt[i]+bt[i];
ss=ss+bt[i];
}
printf("\n\n GANTT CHART");
printf("\n\n ------------------------------------------------------------------\n");
for(i=0;i<n;i++)
{
printf("|\t%s\t",Process[i]);
sbt=sbt+wt[i+1];
tt[i]=wt[i]+bt[i];
ss=ss+bt[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();
}
}
#5
Re: SJF algorithym
Posted 20 January 2009 - 08:26 AM
int randomb=rand() % 1+9;
{
maybe its a stupid question but, why the '{'?
and why do you close it in the end?
#6
Re: SJF algorithym
Posted 20 January 2009 - 08:40 AM
int randomb=rand() % 1+9;
The above is interpreted by the computer as,
Generate a random number between 0 and MaxInteger (2147483647), divide it by 1 and calculate the integer remainder (which is always 0), then add 9 and place the result in variable randomb. I.e the result is always 9.
The above is interpreted by the computer as,
Generate a random number between 0 and MaxInteger (2147483647), divide it by 1 and calculate the integer remainder (which is always 0), then add 9 and place the result in variable randomb. I.e the result is always 9.
This post has been edited by Gloin: 20 January 2009 - 08:41 AM
#7
Re: SJF algorithym
Posted 20 January 2009 - 09:18 AM
Then there's this abomination:
With totally uninitialized data.
To sort of paraphrase Dean Wormer: Copying and pasting code is no way to program.
printf("%s",&Process[i],&bt[randomb]);
With totally uninitialized data.
To sort of paraphrase Dean Wormer: Copying and pasting code is no way to program.
#8
Re: SJF algorithym
Posted 20 January 2009 - 09:23 AM
This code was totaly copy past, and it still needs a lot of work done on it.
I do belive the error you were asking its due to some loose { } around the code.
I do belive the error you were asking its due to some loose { } around the code.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote











|