0% found this document useful (0 votes)
77 views24 pages

Cn&os Lab Executed Codes

The document contains code snippets related to computer networks and operating systems concepts. Specifically, it includes code for: 1) Character stuffing and bit stuffing techniques for data transmission. 2) CRC algorithms for error detection. 3) Sliding window protocol for reliable data transmission. 4) Dijkstra's algorithm and distance vector algorithm for shortest path routing. 5) Scheduling algorithms like FCFS, SJF, priority scheduling, and round robin for process scheduling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views24 pages

Cn&os Lab Executed Codes

The document contains code snippets related to computer networks and operating systems concepts. Specifically, it includes code for: 1) Character stuffing and bit stuffing techniques for data transmission. 2) CRC algorithms for error detection. 3) Sliding window protocol for reliable data transmission. 4) Dijkstra's algorithm and distance vector algorithm for shortest path routing. 5) Scheduling algorithms like FCFS, SJF, priority scheduling, and round robin for process scheduling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 24

COMPUTER NETWORK

1.CHARACTER STUFFING
#include <stdio.h>
#include<string.h>

int main(void) {

int i=0,j,n;
char a[30],b[50];
scanf("%s",&a);
n=strlen(a);
b[0]='D';
b[1]='L';
b[2]='E';
b[3]='S';
b[4]='T';
b[5]='X';
j=6;
while(i<n)
{
if(a[i]=='D' && a[i+1]=='L' && a[i+2]=='E')
{
b[j]='D';
b[j+1]='L';
b[j+2]='E';
j=j+3;
}
b[j]=a[i];
j++;
i++;
}
b[j]='D';
b[j+1]='L';
b[j+2]='E';
b[j+3]='E';
b[j+4]='T';
b[j+5]='X';
b[j+6]='\0';
printf("%s",b);
return 0;
}
2.BIT STUFFING
#include<stdio.h>
int main()
{

int i,j,k,count,n,a[20],b[30];
printf("Enter the frame size");
scanf("%d",&n);
printf("Enter the frame(in 0s and 1s)\n");
for(int i=0;i<n;i++)
scanf("%d",&a[i]);

i=0;
j=0;
count=1;
while(i<n)
{
if(a[i]==1)
{
b[j]=a[i];
for(k=i+1;k<n && count<5 && a[k]==1;k++)
{
j++;
b[j]=a[k];
count++;

if(count==5)
{
j++;
b[j]=0;
}i=k;
}
}
else
{
b[j]=a[i];
}
i++;
j++;
}
printf("Frames after stuffing is : \n");
for(i=0;i<j;i++)
printf("%d",b[i]);
return 0;
}
3.CRC
#include<stdio.h>
char data[20],div[20],temp[4],total[100];
int i,j,datalen,divlen,len,flag=1;
void check();
int main()
{
printf("Enter the total bit of data:");
scanf("%d",&datalen);
printf("\nEnter the total bit of divisor");
scanf("%d",&divlen);
len=datalen+divlen-1;
printf("\nEnter the data:");
scanf("%s",&data);
printf("\nEnter the divisor");
scanf("%s",div);

for(i=0;i<datalen;i++)
{
total[i]=data[i];
temp[i]=data[i];
}
for(i=datalen;i<len;i++)
total[i]='0';
check();
for(i=0;i<divlen;i++)
temp[i+datalen]=data[i];
printf("\ntransmitted Code Word:%s",temp);
printf("\n\nEnter the received code word:");
scanf("%s",total);
check();
for(i=0;i<divlen-1;i++)
if(data[i]=='1')
{
flag=0;
break;
}
if(flag==1)
printf("\nsuccessful!!");
else
printf("\nreceived code word contains errors...\n");
}
void check()
{
for(j=0;j<divlen;j++)
data[j]=total[j];
while(j<=len)
{
if(data[0]=='1')
for(i = 1;i <divlen ; i++)
data[i] = (( data[i] == div[i])?'0':'1');
for(i=0;i<divlen-1;i++)
data[i]=data[i+1];
data[i]=total[j++];
}
}

4.SLIDING WINDOW PROTOCOL

#include <stdio.h>
int main()
{
int i, w, f, frames[50];
printf("Enter the window size");
scanf("%d", &w);
printf("\n Enter the number of frames to be transmitted");
scanf("%d", &f);
printf("\n Enter the %d frames", f);
for (i = 1; i<= f; i++)
scanf("%d", &frames[i]);
printf("\n With sliding window protocol the frames will be sent in following manner (assuming no
corruotion of frames)\n\n");
printf("After sending %d frames at each stages sender waits for acknowledgeent sent by receiver\n\
n", w);
for (i = 1; i<= f; i++)
{
if (i % w == 0)
{
printf("%d", frames[i]);
printf("Acknowledgement of abouve frames sent is received by sender\n\n");
}
else
printf("%d", frames[i]);
}
if (f % w != 0)
printf("Acknowledgement of above frames sent is received by sender\n\n");

return 0;
}
5.DIJIKSTRAS ALGORITHM
# include <stdio.h>
#define INFINITY 9999
#define MAX 10

void dijkstra(int G[MAX][MAX],int n,intstartnode);


int main()
{
int G[MAX][MAX],i,j,n,u;
printf("Enter the number of vertices\n");
scanf("%d",&n);
printf("Ener the adjecency matrix \n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i][j]);

printf("\n Enter the starting node");


scanf("%d",&u);
dijkstra(G,n,u);
return 0;
}
void dijkstra(int G[MAX][MAX],int n,intstartnode)
{
int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];
for(i=0;i<n;i++)
{
distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}
distance[startnode]=0;
visited[startnode]=1;
count=1;
while(count< n-1)
{
mindistance = INFINITY;
for(i=0;i<n;i++)
if(distance[i]<mindistance&& !visited[i])
{
mindistance=distance[i];
nextnode=1;
}visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance + cost[nextnode][i]<distance[i])
{
distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
}
count++;
}for(i=0;i<n;i++)
if(i!=startnode)
{
printf("\n Distance of node %d = %d",i,distance[i]);
printf("\n path= %d",i);
j=i;
do
{
j=pred[j];
printf("<-%d",j);
}
while(j!=startnode);
}
}

6.DISTANCE VECTOR ALGORITHM


#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
{
int dmat[20][20];
int i,j,k,count=0,n;
printf("Enter the number of nodes\n");
scanf("%d",&n);
printf("\n Enter the cost matrix ;\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
}
do
{
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j] >dmat[i][k]+rt[k].dist[j])
{
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}
} while(count!=0);
for(i=0;i<n;i++)
{
printf("\n\n state value for router %d id \n",i+1);
for(j=0;j<n;j++)
{
printf("\t\n node %d via %d Distance %d ",j+1,rt[i].from[j]+1,rt[i].dist[j]);
}
}

printf("\n\n");

OPERATING SYSTEMS
WEEK 1
7.FCFS

#include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],i,j,n,total=0,pos,temp;
float avg_wt,avg_tat;
printf("Enter number of process:");
scanf("%d",&n);

printf("nEnter Burst Time:n");


for(i=0;i<n;i++)
{
printf("p%d:",i+1);
scanf("%d",&bt[i]);
p[i]=i+1;
}

//sorting of burst times


for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(bt[j]<bt[pos])
pos=j;
}

temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;

temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}

wt[0]=0;

for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];

total+=wt[i];
}

avg_wt=(float)total/n;
total=0;

printf("\nProcesst Burst Time tWaitingTimetTurnaround Time");


for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\np%d\t\t %d\t\t %d\t\t\t%d",p[i],bt[i],wt[i],tat[i]);
}
avg_tat=(float)total/n;
printf("nnAverage Waiting Time=%f",avg_wt);
printf("nAverage Turnaround Time=%fn",avg_tat);
}
8 SJF

#include <stdio.h>
#include <string.h>
//shortest job first ............................................
struct process{

int pid,bt,wt,tt;
}p[10],temp;

int main(void) {
// your code goes here
int i,j,n,totwt,tottt,a1,a2;

printf("Enter the no of process\n");


scanf("%d",&n);
for(int i=1;i<=n;i++)
{
p[i].pid=i;
printf("Enter the burst time\n");
scanf("%d",&p[i].bt);

}
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(p[i].bt>p[j].bt)
{
temp.pid=p[i].pid;
p[i].pid=p[j].pid;
p[j].pid=temp.pid;
temp.bt=p[i].bt;
p[i].bt=p[j].bt;
p[j].bt=temp.bt;
}
}
}
p[1].wt=0;
p[1].tt=p[1].bt+p[1].wt;
i=2;
while(i<=n)
{
p[i].wt=p[i-1].bt+p[i-1].wt;
p[i].tt=p[i].bt+p[i].wt;
i++;

}
i=1;
totwt=tottt=0;
printf("\n processid\tbt\twt\ttt\n");
while(i<=n){

printf("\n %d\t%d\t%d\t%d\n",p[i].pid,p[i].bt,p[i].wt,p[i].tt);
totwt=p[i].wt+totwt;
tottt=p[i].tt+tottt;
i++;

}
a1=totwt/n;
a2=tottt/n;
printf("\n avgwt=%d avgtt=%d\n",a1,a2);

return 0;
}
9.PRIORITY SCHEDULING
#include<stdio.h>
#include<math.h>
struct Job {
int no;
int bt,wt,tat;
int priority;
};
int main()
{
int n,i,j,k;
int com[100]={0};
struct Job J[100];
printf("Enter the number of Jobs");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter Burst Time and priority of Job %d",(i+1));
J[i].no=i+1;
scanf("%d%d",&J[i].bt,&J[i].priority);
}
int current=0;
int completed=0;
int time=0;
while(completed<n)
{
current=n+1;
k=n+1;
for(i=0;i<n;i++)
{
if(com[i]==0 && k>J[i].priority)
{
k=J[i].priority;
current=i;
}
}
if(current!=n+1)
{
i=current;
com[current]=1;
J[i].wt=time;
J[i].tat=time+J[i].bt;
time=time+J[i].bt;
completed++;
}
else
{
break;
}
}
int sumwt,sumtat;
sumwt=0;
sumtat=0;
printf("Job no, Burst Time, Waiting Time, Turn Around Time, Priority\n");
for(i=0;i<n;i++)
{
printf("%d %d %d %d %d\n",J[i].no,J[i].bt,J[i].wt,J[i].tat,J[i].priority);
sumwt=sumwt+J[i].wt;
sumtat=sumtat+J[i].tat;
}
float avgwt,avgtat;
avgwt=sumwt;
avgtat=sumtat;
avgwt=avgwt/n;
avgtat=avgtat/n;
printf("The average waiting time is %fsec\n and the average turn around time is %fsec\
n",avgwt,avgtat);
return 0;
}
10 ROUND ROBIN

#include <stdio.h>
#include <string.h>
//round robin based...........................................
struct process{

int pid,bt,wt,tt;
}p[10],x[10];

int main(void) {
// your code goes here
int i,j,n,tot=0,m,k;
float wttime=0.0,tottime=0.0,a1,a2;

printf("Enter the no of process\n");


scanf("%d",&n);
for(int i=1;i<=n;i++)
{
x[i].pid=i;
printf("Enter the burst time\n");
scanf("%d",&x[i].bt);
tot=tot+x[i].bt;
}
printf("Total burst time : %d",tot);
p[0].tt=0;
k=1;
printf("\nEnter time slice : ");
scanf("%d",&m);
for(j=1;j<=tot;j++)
{
for(i=1;i<=n;i++)
{
if(x[i].bt !=0)
{
p[k].pid=i;
if(x[i].bt-m <0)
{
p[k].wt=p[k-1].tt;
p[k].bt=x[i].bt;
p[k].tt=p[k].wt+x[i].bt;
x[i].bt=0;
k++;
}
else
{
p[k].wt=p[k-1].tt;
p[k].tt=p[k].wt+m;
x[i].bt=x[i].bt-m;
k++;
}
}
}
}
printf("\n Process_id\t Wt\t Tt");
for(i=1;i<=k;i++)
{
printf("\n%d\t%d\t%d",p[i].pid,p[i].wt,p[i].tt);
wttime=wttime+p[i].wt;
tottime=tottime+p[i].tt;
a1=wttime/n;
a2=tottime/n;
}
printf("\nAvg Waiting Time :\t%f ",a1);
printf("\nAvg Turn Around Time :\t%f ",a2);
return 0;
}

WEEK 3
11 PAGING
#include<stdio.h>
int main()
{

int ms, ps, nop, np, rempages, i, j, x, y, pa, offset;


int s[10], fno[10][20];

printf("\nEnter the memory size -- ");

scanf("%d",&ms);

printf("\nEnter the page size -- ");

scanf("%d",&ps);

nop = ms/ps;
printf("\nThe no. of pages available in memory are -- %d ",nop);

printf("\nEnter number of processes -- ");


scanf("%d",&np);

rempages = nop;
for(i=1;i<=np;i++)

printf("\nEnter no. of pages required for p[%d]-- ",i);

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

if(s[i] >rempages)
{

printf("\nMemory is Full");

break;

}
rempages = rempages - s[i];

printf("\nEnterpagetable for p[%d] --- ",i);


for(j=0;j<s[i];j++)

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

printf("\nEnter Logical Address to find Physical Address ");

printf("\nEnter process no. and pagenumber and offset -- ");

scanf("%d %d %d",&x,&y, &offset);


if(x>np || y>=s[i] || offset>=ps)
printf("\nInvalid Process or Page Number or offset");

else

pa=fno[x][y]*ps+offset;
printf("\nThe Physical Address is -- %d",pa);

}
12 SEGMENTATION

#include <stdio.h>
#include <math.h>
int sost;
void gstinfo();
void ptladdr();

struct segtab
{
int sno;
int baddr;
int limit;
int val[10];
}st[10];

void gstinfo()
{
int i,j;
printf("\n\tEnter the size of the segment table: ");
scanf("%d",&sost);

for(i=1;i<=sost;i++)
{
printf("\n\tEnter the information about segment: %d",i);
st[i].sno = i;

printf("\n\tEnter the base Address: ");


scanf("%d",&st[i].baddr);
printf("\n\tEnter the Limit: ");
scanf("%d",&st[i].limit);
for(j=0;j<st[i].limit;j++)
{
printf("Enter the %d address Value: ",(st[i].baddr + j));
scanf("%d",&st[i].val[j]);
}
}
}

void ptladdr()
{
int i,swd,d=0,n,s,disp,paddr;

printf("\n\n\t\t\t SEGMENT TABLE \n\n");


printf("\n\t SEG.NO\tBASE ADDRESS\t LIMIT \n\n");
for(i=1;i<=sost;i++)
printf("\t\t%d \t\t%d\t\t%d\n\n",st[i].sno,st[i].baddr,st[i].limit);
printf("\n\nEnter the logical Address: ");
scanf("%d",&swd);
n=swd;
while (n != 0)
{
n=n/10;
d++;
}

s = swd / pow(10,d-1);
disp = swd % (int)pow(10,d-1);

if(s<=sost)
{
if(disp<st[s].limit)
{
paddr = st[s].baddr + disp;
printf("\n\t\tLogical Address is: %d",swd);
printf("\n\t\tMapped Physical address is: %d",paddr);
printf("\n\tThe value is: %d",( st[s].val[disp] ) );
}
else
printf("\n\t\tLimit of segment %d is high\n\n",s);
}

else
printf("\n\t\tInvalid Segment Address \n");
}

void main()
{
char ch;
gstinfo();
do
{
ptladdr();
printf("\n\t Do U want to Continue(Y/N)");
// flushall();
scanf("%c",&ch);
}while (ch == 'Y' || ch == 'y' );
}
Week 5
13 sequential file allocattion

//SEQUENTIAL FILE ALLOCATION


#include<stdio.h>

struct fileTable
{
char name[20];
int sb,nob;
}ft[30];

void main()
{
int i,j,n;
char s[20];
printf("Enter no of files :");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
printf("\n Enter the file name %d",i+1);
scanf("%s",&ft[i].name);
printf("Enter starting block of file %d",i+1);
scanf("%d",&ft[i].sb);
printf("Enter no of blocks in file %d",i+1);
scanf("%d",&ft[i].nob);
}
printf("Enter the file name to be searched--");
scanf("%s",s);
for(int i=0;i<n;i++)
{
if(strcmp(s,ft[i].name)==0)
{
printf("\nFILE NAME\t START BLOCK\t NO.OF.BLOCKS\t OCCUPIED\n");
printf("%s\t\t\t %d\t\t\t\t %d\t\t\t\t ",ft[i].name,ft[i].sb,ft[i].nob);
for(int j=0;j<ft[i].nob;j++)
{
printf("%d ",ft[i].sb+j);
}
}
else if(i==n)
printf("File not found\n");
}

}
14 Linked list file allocation

//LINKED LIST FILE ALLOCATION


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct fileTable
{
char name[20];
int nob;
struct block *sb;
}ft[30];

struct block
{
int bno;
struct block *next;
};
void main()
{
int i,j,n;
char s[20];
struct block *temp;
printf("Enter no of files :");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
printf("\n Enter the file name %d",i+1);
scanf("%s",&ft[i].name);
printf("Enter no of blocks in file %d",i+1);
scanf("%d",&ft[i].nob);
ft[i].sb=(struct block*)malloc(sizeof(struct block));
temp=ft[i].sb;
printf("Enter blocks of file :");
scanf("%d",&temp->bno);
temp->next=NULL;
for(int j=1;j<ft[i].nob;j++)
{
temp->next=(struct block*)malloc(sizeof(struct block));
temp=temp->next;
scanf("%d",&temp->bno);
}
temp->next=NULL;
}
printf("Enter the file name to be searched--");
scanf("%s",&s);
for(int i=0;i<n;i++)
{
if(strcmp(s,ft[i].name)==0)
{
printf("\nFILE NAME\t NO.OF.BLOCKS\t OCCUPIED\n");
printf("%s\t\t\t %d\t\t\t\t ",ft[i].name);
temp=ft[i].sb;
for(int j=0;j<ft[i].nob-1;j++)
{
printf("%d->",temp->bno);
temp=temp->next;
}
}
else if(i==n)
printf("File not found\n");
}

}
15 Indexed file allocation

//INDEXED FILE ALLOCATION


#include<stdio.h>
#include<string.h>
struct fileTable
{
char name[20];
int nob,blocks[30];
}ft[30];

void main()
{
int i,j,n;
char s[20];
printf("Enter no of files :");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
printf("\n Enter the file name %d",i+1);
scanf("%s",&ft[i].name);
printf("Enter no of blocks in file %d",i+1);
scanf("%d",&ft[i].nob);
printf("Enter the blocks of file :");
for(j=0;j<ft[i].nob;j++)
{
scanf("%d",&ft[i].blocks[j]);
}
}
printf("Enter the file name to be searched--");
scanf("%s",s);
for(int i=0;i<n;i++)
{
if(strcmp(s,ft[i].name)==0)
{
printf("\nFILE NAME\t NO.OF.BLOCKS\t OCCUPIED\n");
printf("%s\t\t\t %d\t\t\t\t ",ft[i].name,ft[i].nob);
for(j=0;j<ft[i].nob-1;j++)
{
printf("%d,",ft[i].blocks[j]);
}
printf("%d",ft[i].blocks[ft[i].nob-1]);
}
else if(i==n)
printf("File not found\n");
}

16. //week-6
//FCFS
// Online C compiler to run C program online
#include <stdio.h>

int main() {
int n;
// printf("enter the np of tracks");
// scanf("%d",&n);
int p,s[100],a;
printf("enter the starting pos and no of tracks to traverse\n");
scanf("%d%d",&p,&a);
printf("enter the tracks:");
int dummy=p,c=0,b=0;
for(int i=0;i<a;i++)
{
scanf("%d",&s[i]);
if(s[i]-dummy<0)
{
c=(-1)*(s[i]-dummy);
}
else
{
c=s[i]-dummy;
}
dummy=s[i];
printf("Tracks traversed:%d \t difference is:%d\n",s[i],c);
b+=c;

printf("The avg seek time is:%f\n",(float)b/a*1.0);


return 0;
}

17. //SCAN
// Online C compiler to run C program online
#include <stdio.h>

int main() {
int n;
printf("enter the no of tracks");
scanf("%d",&n);
int p,s[100],a;
printf("enter the starting pos and no of tracks to traverse\n");
scanf("%d%d",&p,&a);
printf("enter the tracks:");
int dummy=p,c=0,b=0;
for(int i=0;i<a;i++)
{
scanf("%d",&s[i]);

}
//sorting
for(int i=0;i<a;i++)
{
for(int j=0;j<a;j++)
{
if(s[i]<s[j])
{
int temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
//traversing towards right first;
for(int i=0;i<a;i++)
printf("%d\n",s[i]);
for(int i=0;i<a;i++)
{
if(s[i]>p)
{
dummy=s[i];
c=i;
break;
}

b+=dummy-p;
int d=dummy-p;
for(int i=c;i<a;i++)
{
printf("traversing:%d ",s[i]);
printf("diff :%d\n",d);
dummy=s[i];
d=s[i+1]-s[i];
b+=d;
}
b+=n-s[a-1];//in scan until last track is traversed
d=s[a-1];
for(int i=c-1;i>=0;i--)
{printf("traversing:%d ",s[i]);
printf("diff :%d\n ",d-s[i]);

b+=d-s[i];
d=s[i];

printf("The avg seek time is:%f\n",(float)b/a*1.0);


return 0;
}

18. //CSCAN(circular scan)

// Online C compiler to run C program online


#include <stdio.h>

int main() {
int n;
printf("enter the no of tracks");
scanf("%d",&n);
int p,s[100],a;
printf("enter the starting pos and no of tracks to traverse\n");
scanf("%d%d",&p,&a);
printf("enter the tracks:");
int dummy=p,c=0,b=0;
for(int i=0;i<a;i++)
{
scanf("%d",&s[i]);

}
//sorting
for(int i=0;i<a;i++)
{
for(int j=0;j<a;j++)
{
if(s[i]<s[j])
{
int temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
//traversing towards right first;
for(int i=0;i<a;i++)
printf("%d\n",s[i]);
for(int i=0;i<a;i++)
{
if(s[i]>p)
{
dummy=s[i];
c=i;
break;
}

b+=dummy-p;
int d=dummy-p;
for(int i=c;i<a;i++)
{
printf("traversing:%d ",s[i]);
printf("diff :%d\n",d);
dummy=s[i];
d=s[i+1]-s[i];
b+=d;
}
b+=n;
//in cscan until last track is traversed and
//again until the first track is traversed
d=0;
for(int i=0;i<c;i++)
{printf("traversing:%d ",s[i]);
printf("diff :%d\n ",s[i]-d);
b+=s[i]-d;
d=s[i];

printf("The avg seek time is:%f\n",(float)b/a*1.0);


return 0;
}

You might also like