Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
18 views3 pages

Job Sequence With Multiple Deadlines

The document presents a C program that implements a job sequencing algorithm with multiple deadlines, allowing users to input profits and deadlines for various jobs. It sorts the jobs based on profit and assigns them to available slots before their deadlines to maximize total profit. The output displays the optimal job sequence and the total profit achieved.

Uploaded by

golladeepu19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views3 pages

Job Sequence With Multiple Deadlines

The document presents a C program that implements a job sequencing algorithm with multiple deadlines, allowing users to input profits and deadlines for various jobs. It sorts the jobs based on profit and assigns them to available slots before their deadlines to maximize total profit. The output displays the optimal job sequence and the total profit achieved.

Uploaded by

golladeepu19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Job sequence with multiple deadlines:

#include<stdio.h>

void main()

int i,j,p[20],d[20],a[20],slot[20],temp,r,total=0,max,n;

printf("\nenter no.of objects");


scanf("%d",&n);

printf("\nenter profit");

for(i=0;i<n;i++)

scanf("%d",&p[i]);

printf("\nenter deadline");

for(i=0;i<n;i++)

scanf("%d",&d[i]);
}

max=d[0];

for(i=0;i<n;i++)

{
a[i]=i;

if(d[i]>max)

max=d[i];

for(i=0;i<max;i++)

slot[i]=-1;
for(i=0;i<n-1;i++)
{

for(j=0;j<n-1-i;j++)

if(p[j]<p[j+1])

temp=p[j];
p[j]=p[j+1];

p[j+1]=temp;

temp=a[j];
a[j]=a[j+1];

a[j+1]=temp;

for(i=0;i<n;i++)

j=a[i];
r=d[j];

while(r>=1)

if(slot[r-1]==-1)

{
slot[r-1]=j;

total=total+p[i];

break;

r--;

}
printf("optimal solution is:\n(");
for(i=0;i<max;i++)

printf("j%d",slot[i]+1);

if(i<max-1)

printf(" , ");

}
printf(")");

printf("\nTotal profit:%d",total);

Output:
enter no.of objects5

enter profit10

15

20

enter deadline1

3
optimal solution is:

(j3 , j4 , j2)

Total profit:40

You might also like