Author: Alagappan Karthikeyan

C Program to Search an Array Element using BINARY SEARCH

include void binary_search(); int a[50], n, item, loc, beg, mid, end, i;void main(){printf(“\nEnter size of an array: “);scanf(“%d”, &n);printf(“\nEnter elements of an array in sorted form:\n”);for(i=0; i<n; i++)scanf(“%d”, &a[i]);printf(“\nEnter ITEM to be searched: “);scanf(“%d”, &item);binary_search();getch();}void binary_search(){beg = 0;end = n-1;mid = (beg + end) / 2;while ((beg<=end) && (a[mid]!=item)){if (item < a[mid])end = mid – …

Start reading C Program to Search an Array Element using BINARY SEARCH

C Program to Implement Structure with Pointers

include struct student{char name[30];int rollno;float marks;};void display(struct student *);void main(){struct student s1 = {“Raja”, 538, 92};display(&s1);getch();}void display(struct student *ptr){printf(“Student name\tRollno\tMarks\n”);printf(“%s\t\t%i\t%f”,ptr->name,ptr->rollno,ptr->marks);} OUTPUT:Student name Rollno MarksRaja 538 92.000000

Start reading C Program to Implement Structure with Pointers

C Program to Implement Structure with Functions

include struct student{char name;int rollno;float marks;};struct student std_func(char, int, float);main(){struct student s1 = {‘X’, 125, 95};std_func(s1.name, s1.rollno, s1.marks);getch();}struct student std_func(char name, int rollno, float marks){printf(“Name\tRoll No.\tMarks\n”);printf(“%c\t%d\t\t%.2f”, name, rollno, marks);} OUTPUT:Name Roll No. MarksX 125 95.00

Start reading C Program to Implement Structure with Functions

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