This is an CPU sheduling algorithm i.e proirity sheduling .It show some error that i can't solve please anyone correct it . its very urgent.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],b[20],c[20],e[20],d[10],totaltime;
int att,at,aw,awt,t1,i,j,n;
clrscr();
printf("\n\t\t\tpriority scheduling");
printf("\nEnter the no of process: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n");
printf("\nprocess: ");
printf("%d",i+1);
c[i]=i+1;
printf("\n\t");
printf("Time: ");
scanf("%d",&a[i]);
printf("\n\t");
printf("\n\tPriority: ");
scanf("%d",&b[i]);
}
printf("\n\nThe priority based order is: ");
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(b[i]>b[j])
{
t1=b[i];
b[i]=b[j];
b[j]=t1;
t1=a[i];
a[i]=a[j];
a[j]=t1;
t1=c[i];
c[i]=c[j];
c[j]=t1;
}
}
}
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(b[i]==b[j])
{
if(i>j)
{
t1=b[i];
b[i]=b[j];
b[j]=t1;
}
}
}
}
for(i=0;i<n;i++)
{
printf("\nProcess %d%d",c[i],b[i]);
}
printf("\n\n\t\t");
printf("\t\tGANNT CHART");
printf("\n\t\t\t");
for(i=0;i<n;i++)
{
printf("--------------");
}
printf("\n\t\t\t");
for(i=0;i<n;i++)
{
printf("|p%d=%d\t|",c[i],b[i]);
}
for(i=0;i<n;i++)
{
printf("--------------");
}
printf("\n\t\t\t");
totaltime=0;
for(i=0;i<n;i++)
{
e[i]=totaltime;
totaltime=totaltime +a[i];
d[i]=totaltime;
}
printf("\n\t\t\t");
printf("0";
for(i=0;i<n;i++)
{
printf("\t%d",d[i]);
}
aw=0;
awt=0;
for(i=0;i<n-1;i++)
{
aw=aw+d[i];
}
awt=aw/n;
printf("\n\n\n\n");
printf("Process\t\twaittime\t\tturntime\n");
for(i=0;i<n;i++)
{
printf("\n%d\t\t%d\t\t%d\t\t",c[i],i+1,e[i],d[i]);
}
printf("\n\n");
printf("\nThe total execution time is :%d",totaltime);
printf("\nThe average waiting time is:%d",awt);
at=0;
att=0;
for(i=0;i<n;i++)
{
at=at+d[i];
}
att=at/n;
printf("\nThe average turn around time is :%d",att);
getch();
}

Recommended Answers

All 3 Replies

This is an CPU sheduling algorithm i.e proirity sheduling .It show some error that i can't solve please anyone correct it . its very urgent.

1) This is not a CODE SNIPPET. Do not post questions as such
2) Help Me is a title in violation of the Forum Rules. You did read them as requested, right?
3) How do you expect anyone to follow unformatted code? Formatting is necessary when writing code.
4) Nothing is urgent on this forum. If it's really urgent, talk to your instructor.
5) You expect us to figure out what your error is with no information from you? Presumptuous, isn't it?
6) You expect us to fix your code for you? Contact hire-a-coder.

commented: Excellent +19

once you address what walt said, your first code problem i see is <conio.h>

remove that line, and remove everything that depends on it. then rewrite in standard C.

until you do that, i doubt anyone here will bother trying to compile and run your code, because no one uses the joke of a shitty compiler that continues to use that deprecated library.

I would advise you to use structures instead of so many arrays. Swapping structures is as easy as a=b
This will reduce the chances of error in your code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.