FIRST COME FIRST SERVE PROGRAM USING C

#include<stdio.h>
void swap(int *arr,int i,int j)
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
void sort(int at[],int bt[],int n)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(at[j]>at[j+1])
{
swap(at,j,j+1);
swap(bt,j,j+1);
}
}
}
}
void main()
{
int n;
int i;
int at[10],bt[10],ct[10],tat[10],wt[10];
printf("enter number of process : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter at and bt of process [%d]: ",i+1);
scanf("%d %d",&at[i],&bt[i]);
}
sort(at,bt,n);
for(i=0;i<n;i++)
{
if(i==0)
{
ct[i]=at[i]+bt[i];
tat[i]=ct[i]-at[i];
wt[i]=tat[i]-bt[i];
}
else
{
if(ct[i-1]<at[i])
{
ct[i]=at[i]+bt[i];
}
else
{
ct[i]=ct[i-1]+bt[i];
}
tat[i]=ct[i]-at[i];
wt[i]=tat[i]-bt[i];
}
}
printf("ct tat wt\n");
for(i=0;i<n;i++)
{
printf("%d %d %d\n",ct[i],tat[i],wt[i]);
}
}

Comments

Popular posts from this blog

BYTE STUFFING PROGRAM USING C

Rotate a matrix 270 degree AntiClockWise

Finding the length of connected cells of 1's (regions) in an matrix of 1's and 0's