Posts

Showing posts with the label C Programs

C program of Cyclic Redundancy Check

Image
C program of Cyclic Redundancy Check    Program #include <stdio.h> // shorthand for loops #define forn(i,e) for(int i = 0; i < e; i++) #define forsn(i,s,e) for(int i = s; i < e; i++) int validate_data( int len_data, int data[], int len_divisor, int divisor[]){ // Returns 1, if the data is correct // Returns 0, if the data is incorrect/corrupted. int current_bits[len_divisor]; forn(i, len_divisor) { current_bits[i] = data[i]; } // the logic is same as generating the crc. forn(i, len_data) { if (!current_bits[ 0 ]) { forn(j, len_divisor- 1 ) { current_bits[j] = current_bits[j+ 1 ]; } current_bits[len_divisor- 1 ] = data[i+len_divisor]; } else { forn(j, len_divisor) { current_bits[j] = current_bits[j]^divisor[j]; } forn(j, len_divisor- 1 ) { current_bits[j] = current_bits[j+ 1 ]; } current_bits[len_divi...

Practice examples on c language for beginners

Image
Solve these questions by your own:  Q.1. Who designed and written C language? (a)                                           (b) Dennis Ritchie (c)                                            (d) Q.2. In C language array fall under which category of constants? (a) Primary                          (b) Secondary Q.3. Which of the following int variable eligible to stored? (a) 264         ...

Doubly Linklist | Data Structure | C Program

Image
Doubly Link-list: INSERT AT BEGINNING: struct node *temp1,*temp2; temp1=(struct node*)malloc(sizeof(struct node)); printf("Enter value to insert:\n"); scanf("%d",&temp1->info); temp1->next=NULL; temp1->pre=NULL; if(start==NULL) start=temp1; else { temp1->next=start; start->pre=temp1; start=temp1; } INSERT AT GIVEN POSITION: int i,pos; struct node *temp1,*temp2; temp1=(struct node*)malloc(sizeof(struct node)); printf("Enter the postion:\n"); scanf("%d",&pos); printf("Enter value:\n"); scanf("%d",&temp1->info); temp1->next=NULL; temp1->pre=NULL; if(start==NULL) start=temp1; else if(pos==1) { temp1->next=start; start->pre=temp1; start=temp1; } else { temp2=start; for(i=1;i<pos-1;i++) temp2=temp2->next; temp1->next=temp2->next; temp2->next=temp1; temp1->pre=temp2; temp1->next->pre=temp1; } INSERT AT END: struct node...

Circular Linklist | Data Structure | C Program

Image
Circular link list : Code: INSERT AT BEGINNING: struct node *temp1,*temp2; temp1=(struct node*)malloc(sizeof(struct node)); temp2=start; printf("Enter value insert:\t"); scanf("%d",&temp1->info); if(start==NULL) { start=temp1; temp1->link=start; } else { while(temp2->link!=start) temp2=temp2->link; temp2->link=temp1; temp1->link=start; start=temp1; } } INSERT AT GIVEN POSITION: void cr_mid() { int i,pos; struct node *temp1,*temp2; temp2=start; temp1=(struct node*)malloc(sizeof(struct node)); printf("Enter the postion:\n"); scanf("%d",&pos); printf("Enter value to insert:\t"); scanf("%d",&temp1->info); for(i=1;i<pos-1;i++) temp2=temp2->link; temp1->link=temp2->link; temp2->link=temp1; } INSERT AT END: void cr_end() { struct node *temp1,*temp2; temp1=(struct node*)malloc(sizeof(struct node)); temp2=start; printf("Enter value to insert:\n...

SINGLY Linked List | Data Structure | C Program

Image
Singly link list : Code: INSERT AT BEGINNING: in_beg() { struct node *temp; int item; temp=(struct node*)malloc(sizeof(struct node)); printf("Enter a value :\n"); scanf("%d",&item); temp->info=item; temp->link=start; start=temp; } INSERT AT GIVEN POSITION: void de_mid() { struct node *temp1,*temp2; int i,pos; if(start==NULL) printf("List is empty!!\n"); else { temp1=start; printf("Enter the postion:\t"); scanf("%d",&pos); for(i=1;i<=pos-1;i++) temp2=temp1; temp1=temp1->link; temp2->link=temp1->link; free(temp1); } } INSERT AT END: void in_end() { struct node *temp1,*temp2; int item; temp1=(struct node*)malloc(sizeof(struct node)); printf("Enter a number:\t"); scanf("%d",&item); temp2=start; temp1->info=item; temp1->link=NULL; if(start==NULL) start=temp1; else { while(temp2->link!=NULL) temp2=temp2->...