Home
Se complete record
O.S notes
DBMS complete notes
Java all programs
Price per kg calc
CN lab internal
By
Ashish Singh
September 06, 2022
๐๐ To paste in putty just right click on terminal๐๐
1. Bitstuffing
//Program:(bit-stuffing) #include
main() { int i,k,a,count=0; char c[50]; printf("\nEnter the data to be send:"); fflush(stdin); gets(c); a=strlen(c); for(i=0;i
i+1;k--) c[k]=c[k-1]; a=a+1; count=0; c[i+1]='0'; } } else count = 0; } printf("\nData after stuffing:"); puts(c); count=0; for(i=0;i
Copy it ❐
1.i character stuffing
//Program:(character-stuffing) #include
main() { char a[50],b[50],c[50]; int i,j,k,m=0,count,l1,l2; printf("\nEnter the data to send:"); fflush(stdin); gets(a); printf("\nEnter the delimeter:"); fflush(stdin); gets(b); l1=strlen(a); l2=strlen(b); c[0]='S'; for(i=0;i
m;k--) a[k]=a[k-l2]; for(k=0;k
Copy it ❐
2. CRC
//Program: crc #include
#include
int main() { int i,j,k=0; int flag=1,a[16],g[16],r[20],div[16],n,m; system("clear"); printf("Enter degree of generator:"); scanf("%d",&n); printf("\n Enter the generator:\n"); for(i=0;i<=n;i++) scanf("%d",&g[i]); printf("\nEnter the degree of the frame:"); scanf("%d",&m); printf("Enter the frame:\n"); for(i=0;i<=m;i++) scanf("%d",&a[i]); if(m
n) { for(j=0;j
n) { for(j=0;j
Copy it ❐
3. Sliding window protocol
//program sliding window protocol #include
int main() { int w,i,f,frames[50]; printf("Enter window size: "); scanf("%d",&w); printf("\nEnter number of frames to transmit: "); scanf("%d",&f); printf("\nEnter %d frames: ",f); for(i=1;i<=f;i++) scanf("%d",&frames[i]); printf("\nWith sliding window protocol the frames will be sent in the following manner assuming:\n"); printf("After sending %d frames at each stage sender waits for acknowledgement sent by ther\n",w); for(i=1;i<=f;i++) { if(i%w==0) { printf("%d\n",frames[i]); printf("Acknowledgement of above frames sent is received by sender\n\n"); } else printf("%d ",frames[i]); } if(f%w!=0) printf("\nAcknowledgement of above frames sent is received by sender\n"); return 0; } /* Output Enter window size: 3 Enter number of frames to transmit: 5 Enter 5 frames: 12 5 89 4 6 With sliding window protocol the frames will be sent in the following manner (assuming no corruption of frames) After sending 3 frames at each stage sender waits for acknowledgement sent by the receiver 12 5 89 Acknowledgement of above frames sent is received by sender 4 6 Acknowledgement of above frames sent is received by sender */
Copy it ❐
4. Dijkastras
//program Dijkastras #include
#include
//#include
#define M_NODES 10 #define INFINITY 1000 int n,dis[M_NODES][M_NODES]; void main() { void spath(int,int); int i,j,g[100][100],s,t,c; printf("\nEnter number of nodes:"); scanf("%d",&n); for(i=0;i
%d\t",i,j); scanf("%d",&c); if(c>=0) dis[i][j]=c; else exit(0); } } printf("\nEnter source and destination nodes:"); scanf("%d%d",&t,&s); spath(s,t); //getch(); } void spath(int s,int t) { struct state { int pre,len; enum{permanet,tentative} label; }state[M_NODES]; int i,k,min,path[20],c=0; struct state *p; for(p=&state[0];p<&state[n];p++) { p->pre=-1; p->len=INFINITY; p->label=tentative; } state[t].len=0; state[t].label=permanet; k=t; do { for(i=0;i
=0); printf("\nMinimum Cost is=%d",min); printf("\nShortest path is="); for(k=c-1;k>=0;k--) printf("%d-->",path[k]); } /*Output: Enter number of nodes:5 Enter weight between 0-->0 0 Enter weight between 0-->1 1 Enter weight between 0-->2 7 Enter weight between 0-->3 2 Enter weight between 0-->4 0 Enter weight between 1-->1 0 Enter weight between 1-->2 3 Enter weight between 1-->3 4 enter source and destination node 0 3 minimum cost is 2 */
Copy it ❐
0 Comments
Follow Us
Powered by Blogger
0 Comments