Category: Programs

C Program to Delete Characters from Given String

/* Write a C program to delete n Characters from a given position in a given string.*/ include include include void delchar(char *x,int a, int b); main(){char string[10];int n,pos,p;//clrscr(); } // Function to delete n charactersvoid delchar(char *x,int a, int b){if ((a+b-1) <= strlen(x)){strcpy(&x[b-1],&x[a+b-1]);puts(x);}} OUTPUT:Enter a string :programming9Enter the position from where you want to …

Start reading C Program to Delete Characters from Given String

C Program to Sort an Array using SELECTION SORT

include void selection_sort();int a[30], n;void main(){int i;printf(“\nEnter size of an array: “);scanf(“%d”, &n);printf(“\nEnter elements of an array:\n”);for(i=0; i<n; i++)scanf(“%d”, &a[i]);selection_sort();printf(“\n\nAfter sorting:\n”);for(i=0; i<n; i++)printf(“\n%d”, a[i]);getch();}void selection_sort(){int i, j, min, temp;for (i=0; i<n; i++){min = i;for (j=i+1; j<n; j++){if (a[j] < a[min])min = j;}temp = a[i];a[i] = a[min];a[min] = temp;}} OUTPUT:Enter size of an array: 8 Enter …

Start reading C Program to Sort an Array using SELECTION SORT

C Program to INSERT a Sub-String in Main String at Given Position

/* Write a C program to insert a sub-string in to given main string from a given position.*/ include include int main(){char a[10];char b[10];char c[10];int p=0,r=0,i=0;int t=0;int x,g,s,n,o;//clrscr(); puts(“Enter First String:”);gets(a);puts(“Enter Second String:”);gets(b);printf(“Enter the position where the item has to be inserted: “);scanf(“%d”,&p);r = strlen(a);n = strlen(b);i=0; // Copying the input string into another arraywhile(i …

Start reading C Program to INSERT a Sub-String in Main String at Given Position

C Program to Find Sub String Position in Given String

/* Write a C program that displays the position or index in the string S.*/ include include int main(){char s[30], t[20];char *found; /* Entering the main string */puts(“Enter the first string: “);gets(s); /* Entering the string whose position or index to be displayed */puts(“Enter the string to be searched: “);gets(t); /*Searching string t in string …

Start reading C Program to Find Sub String Position in Given String

C Program to Perform Operations on Doubly Linked List

/* Write a C program to perform the following operations on doubly linked list.:i) Creation ii) Insertion iii) Deletion iv) Traversal in both ways*/ include include typedef struct dubll{int data;struct dubll leftlink,rightlink;}*DUBLL; DUBLL high,temp_node,low,last,pntr;int flag=0; DUBLL NodeAlloc();DUBLL Search(int,int); void CreateItem();void AppendItem();void PrintItem();void DeleteItem();DUBLL Search(int item,int flag);DUBLL NodeAlloc();void InsertItem(); main(void){int choice,Item;high=NULL;while(1){//clrscr();printf(“\n \t\t\t M A I N …

Start reading C Program to Perform Operations on Doubly Linked List

C Program for MERGING of Two Arrays with out using Third Array

include int main() {int n1, n2, i, j, *p, *q, a[10], b[10];printf(“Enter the number of elements in array 1 :: “);scanf(“%d”, &n1); } OUTPUT:Enter the number of elements in array 1 :: 5Enter the elements : 1 2 3 4 5Enter the number of elements in array 2 :: 5Enter the elements : 6 7 …

Start reading C Program for MERGING of Two Arrays with out using Third Array

C Program to Implement Single Linked List Operations

include include struct Node;typedef struct Node * PtrToNode;typedef PtrToNode List;typedef PtrToNode Position; struct Node{int e;Position next;}; void Insert(int x, List l, Position p){Position TmpCell;TmpCell = (struct Node*) malloc(sizeof(struct Node));if(TmpCell == NULL)printf(“Memory out of space\n”);else{TmpCell->e = x;TmpCell->next = p->next;p->next = TmpCell;}} int isLast(Position p){return (p->next == NULL);} Position FindPrevious(int x, List l){Position p = l;while(p->next != …

Start reading C Program to Implement Single Linked List Operations

C Program to Implement Doubly Linked List Operations

struct Node;typedef struct Node * PtrToNode;typedef PtrToNode List;typedef PtrToNode Position; struct Node{int e;Position previous;Position next;}; void Insert(int x, List l, Position p){Position TmpCell;TmpCell = (struct Node*) malloc(sizeof(struct Node));if(TmpCell == NULL)printf(“Memory out of space\n”);else{TmpCell->e = x;TmpCell->previous = p;TmpCell->next = p->next;p->next = TmpCell;}} int isLast(Position p){return (p->next == NULL);} Position Find(int x, List l){Position p = l->next;while(p …

Start reading C Program to Implement Doubly Linked List Operations